I'm trying to perform a VLookup where the column of the data I will be pulling can vary. How can I search for the column name instead of having to give a fixed column number?
Application.VLookup(.Cells(row, 1).value, Worksheets("Sheet1").Range("A2:Z" & lastRow_Sheet1), 4, 0)
Application.VLookup(.Cells(row, 1).value, Worksheets("Sheet1").Range("A2:Z" & lastRow_Sheet1), COLUMNNAME, 0)
I'm trying to get a MATCH function working here but am having no luck:
Application.VLookup(.Cells(row, 1).value, Worksheets("Sheet1").Range("A2:Z" & lastRow_Sheet1), WorksheetFunction.Match("Column Name", "A1:Z1", 0), 0)
Edit: Solution here
Application.VLookup(.Cells(row, 1).value, Worksheets("Sheet1").Range("A2:Z" & lastRow_Sheet1), WorksheetFunction.Match("Column Name", Range("A1:Z1"), 0), 0)
