Extend Fill Down Range to last row

sccardais

New Member
Joined
Aug 30, 2017
Messages
6
I am new to VBA.

The last lines of the recorded macro shown below show an absolute reference for a Fill Down operation (C448). I would like to make the reference dynamic - filling to the last row in the sheet rather than the fixed reference.

How should I modify this macro to do this?

Thank you ...

<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 ; background-color: #ffffff }p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008f00 ; background-color: #ffffff }p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; background-color: #ffffff ; min-height: 13.0px}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #011993 ; background-color: #ffffff }span.s1 {color: #011993 }span.s2 {color: #000000 }</style>Sub Macro3()
'
' Macro3 Macro
' Prepares Daily Activity Report for import into FMP. Creates copy of original data, deletes unnecessary columns, adds calc for unique ID.
'


'
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Original Data"
Sheets("Original Data").Select
Sheets("Original Data").Copy Before:=Sheets(1)
Sheets("Original Data (2)").Select
Sheets("Original Data (2)").Name = "Edit for Import"
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Columns("C:C").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("C1").Select
ActiveCell.FormulaR1C1 = "ID Activity"
Range("C2").Select
ActiveCell.FormulaR1C1 = "=RC[-2]&""-""&RC[-1]"
Range("C2").Select
Selection.AutoFill Destination:=Range("C2:C448")
Range("C2:C448").Select
End Sub
 
Edit in red, try:
Rich (BB code):
Sub Macro3()


    Dim x       As Long
    Dim arr()   As Variant
    
    Application.ScreenUpdating = False
    
    With Sheets("Sheet1")
        .Name = "Original Data"
        .Copy before:=Sheets(1)
    End With
    
    With Sheets("Original Data (2)")
        .Name = "Edit for Import"
        .Cells(1, 1).EntireColumn.Delete shift:=xlToLeft
        .Cells(1, 3).EntireColumn.Insert shift:=xlToRight
        .Cells(1, 3).Value = "ID Activity"
        
        x = .Cells(.Rows.Count, 1).End(xlUp).row
        arr = .Cells(1, 1).Resize(x, 3).Value
        arr(1, 3) = "ID Activity"
        For x = LBound(arr, 1) + 1 To UBound(arr, 1)
            arr(x, 3) = CStr(arr(x, 1)) & "-" & CLng(arr(x, 2))
        Next x
        Cells(1, 1).Resize(UBound(arr, 1), UBound(arr, 2)).Value = arr
        Erase arr
    End With
    
    Application.ScreenUpdating = True
        
End Sub
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,223,911
Messages
6,175,335
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top