I am using a Vlookup on a template that I paste a large report into, then run my macro. My Vlookup data is on three separate sheets in the workbook. If there is a code "4356" in column "G" then column "H", "I", "J" are populated with CITY, STATE, and NAME from a particular store code.
Dim LR As Long, LR2 As Long
LR = Worksheets("Dealer City").Cells(Rows.Count, 1).End(xlUp).Row
LR2 = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
With Worksheets("Sheet1").Range("H2:H" & LR2)
.FormulaR1C1 = "=IF(ISNA(VLOOKUP(RC7,'Dealer City'!R1C1:R" & LR & "C2,2,FALSE)),"""",VLOOKUP(RC7,'Dealer City'!R1C1:R" & LR & "C2,2,FALSE))"
End With
With LR = Worksheets("Dealer State").Cells(Rows.Count, 1).End(xlUp).Row
LR2 = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
End With
With Worksheets("Sheet1").Range("I2:I" & LR2)
.FormulaR1C1 = "=IF(ISNA(VLOOKUP(RC7,'Dealer State'!R1C1:R" & LR & "C2,2,FALSE)),"""",VLOOKUP(RC7,'Dealer State'!R1C1:R" & LR & "C2,2,FALSE))"
End With
With LR = Worksheets("Dealer Names").Cells(Rows.Count, 1).End(xlUp).Row
LR2 = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
End With
With Worksheets("Sheet1").Range("J2:J" & LR2)
.FormulaR1C1 = "=IF(ISNA(VLOOKUP(RC7,'Dealer Names'!R1C1:R" & LR & "C2,2,FALSE)),"""",VLOOKUP(RC7,'Dealer Names'!R1C1:R" & LR & "C2,2,FALSE))"
End With
My problem is that now,is a new Column "D" that contains the same codes. I need my lookups to do the lookup for "G" which has higher priority, but if "G" is empty use column "D" to populate CITY,STATE, NAME
Basically, If Column “G” exists then Lookup, else Lookup “D”
Thanks for any help in advance
Bookmarks