Hi guys,
I'm having a little difficulty in tweaking some vba that I have got from a recorded macro. When I run it, I get the message 'Run-time error 1004, Method Range of Object_Global failed'.
Once I click Debug, the VBA sheet opens. When I close it the macro has done what I wanted it to do without having to change any of the coding. I need the coding to be dynamic and apply to a variable last row.
VBA Coding is below...
I would really appreciate your help with this
Sub Location_Overs_Vlookup()
'
' Location_Overs_Vlookup Macro
'
Dim Lastrow As Long
'
Columns("H:H").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("H1").Value = "Location"
Range("H2", Range("G" & Rows.Count).End(xlUp).Offset(, 1)).FormulaR1C1 = "=VLOOKUP(RC[-2],Overs!C[-7]:C[-2],5,FALSE)"
With Range("$A$1:$Z$1")
Range("H2").AutoFill Destination:=Range("H2:H" & Lastrow)
End With
End Sub
I'm having a little difficulty in tweaking some vba that I have got from a recorded macro. When I run it, I get the message 'Run-time error 1004, Method Range of Object_Global failed'.
Once I click Debug, the VBA sheet opens. When I close it the macro has done what I wanted it to do without having to change any of the coding. I need the coding to be dynamic and apply to a variable last row.
VBA Coding is below...
I would really appreciate your help with this
Sub Location_Overs_Vlookup()
'
' Location_Overs_Vlookup Macro
'
Dim Lastrow As Long
'
Columns("H:H").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("H1").Value = "Location"
Range("H2", Range("G" & Rows.Count).End(xlUp).Offset(, 1)).FormulaR1C1 = "=VLOOKUP(RC[-2],Overs!C[-7]:C[-2],5,FALSE)"
With Range("$A$1:$Z$1")
Range("H2").AutoFill Destination:=Range("H2:H" & Lastrow)
End With
End Sub