I have am having trouble with this line in my macro below.
The code is supposed to change the named range in the formula based on the sheet name. I can't figure out why I am getting this error.
Code:
Range("J2:J" & LastRow).Value = "=IFERROR(VLOOKUP(H2," & LCase(sh.Name) & "_rate,3,FALSE),"""")"
Code:
Sub macro()
Dim sh As Variant
For Each sh In Array("vr1", "vr2", "vr3", "ht1", "ht2", "ht3")
Sheets(sh).Columns.AutoFit
Sheets(sh).Columns.HorizontalAlignment = xlLeft
Sheets(sh).Columns("L:M").ColumnWidth = 10
Sheets(sh).Columns("N:P").ColumnWidth = 4
Sheets(sh).Columns("R:T").ColumnWidth = 30
Sheets(sh).Columns("H:I").HorizontalAlignment = xlCenter
Sheets(sh).Columns("N:P").HorizontalAlignment = xlCenter
Dim LastRow As Long
LastRow = Range("B" & Rows.Count).End(xlUp).Row 'find last row in dataset
Range("N2:N" & LastRow).Value = "=IFERROR(VLOOKUP(B2,cam_pivot,2,FALSE),"""")"
Range("O2:O" & LastRow).Value = "=IFERROR(VLOOKUP(B2,auto_pivot,2,FALSE),"""")"
Range("P2:P" & LastRow).Value = "=IFERROR(VLOOKUP(B2,per_pivot,2,FALSE),"""")"
Range("J2:J" & LastRow).Value = "=IFERROR(VLOOKUP(H2," & LCase(sh.Name) & "_rate,3,FALSE),"""")"
Range("K2:K" & LastRow).Value = "=PRODUCT(I2,J2)" 'tally rate * qty
Next sh
Worksheets("VR1").Activate
Range("A2").Select
End Sub