• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to find last row and paste the formula to the last cell of column

Status
Not open for further replies.

AmitSingh

Member
Hi All,
Need help to find the last row in column and paste the H2 formula up to last column till the data is present in last row. Used below code but not getting success. Also code will automatically add column name Mid value in H column. Example if cell H2 contains a formula of mid(G2,20,2) will give P2 value. And that formula should copy till last used row of that column and paste the formula.
I am also adding 3 columns through code named Mid Value, Time Cal and Time in Minutes
Please change the destination of source file according to your convenient.

Moderator: This is third version of same thread.
Do not open always new Your own thread, use Your just done thread.

>>> use code - tags <<<

Code:
Option Explicit
Sub Timecalculation()
Dim wb As Workbook
Dim wks As Worksheet
Dim objList As ListObject
Dim LastRow As Long
Dim sht As Worksheet
 
Set wb = Workbooks.Open("C:\Users\Desktop\SourceData.xlsx")
wb.Sheets("Data").Activate
For Each wks In ActiveWorkbook.Worksheets
    For Each objList In wks.ListObjects
        objList.Unlist
     Next objList
Next wks
Range("H1").Select
'adding column for Mid Value
Set sht = ActiveSheet
Columns("H:H").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("H1").Value = "Mid Value"
ActiveSheet.Range("H2").Select
ActiveCell.FormulaR1C1 = "=Mid(RC[-1],20,2)"
Selection.Copy
Range("H3").Select
LastRow = Range("H" & Rows.Count).End(xlUp).Row
Range("H2:H" & LastRow).Formula = "=&H2"
Range("I1").Select
ActiveSheet.AutoFilterMode = False
'Adding column for time calculate
Columns("I:I").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("I1").Value = "Time Cal"
Range("J1").Select
'Adding column for time in Minutes
Columns("J:J").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("J1").Value = "Time In Minutes"

Application.DisplayAlerts = False

End Sub


Thanks & Regards,
Amit
 

Attachments

  • Calculate Time.xlsb
    28.7 KB · Views: 0
  • SourceData.xlsx
    48.4 KB · Views: 0
Last edited by a moderator:
Status
Not open for further replies.
Back
Top