I'm trying to automate a spreadsheet as much as possible but I'm running into issues with filling down to the last row, and I can't find a solution that works for me.
The number of rows containing data changes on a monthly basis, so I need a dynamic range rather than static.
This code works for a static range:
Sub InsertFormula()
ActiveCell.Formula = "=IFERROR(VLOOKUP(A4, 'SI Report'!$A$2:$F$158, 4, 0), 0)"
Dim LastRow As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
ActiveCell.AutoFill Destination:=Range("F4:F200"), Type:=xlFillValues
End Sub
So I've been trying to build on it to convert to a dynamic range. I've tried the below, but I get an error
"Run-time error '1004': Method 'Range' of object '_Global' failed":
Sub InsertFormula()
ActiveCell.Formula = "=IFERROR(VLOOKUP(A4, 'SI Report'!$A$2:$F$158, 4, 0), 0)"
Dim LastRow As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
ActiveCell.AutoFill Destination:=Range(ActiveCell & LastRow), Type:=xlFillValues
End Sub
Can anyone help, please?