I’m a total noob at VBA and need all the help I can get so I apologise in advance for the dumb question. I feel its the only way I will learn.
I have a spreadsheet with two columns, I simply want to search column A for a particular value (I know what this value is, so can hardcode the value into the code) and return the value in column B and assign it to a variable.
Column A Column B Parameter Value TabDocumentPath Path 1 FrameworkPath Path 2 FrameworkAllFile Path 3 FrameworkFullPath Path 4 AssembliesPath Path 5
So for example if you look at the above, I would like to search for AssembliesPath in Column A and assign the value in the adjacent cell (Path 5) to a variable.
I know, its quite simple but I cannot seem to find this when I search the archive here.
Any help would be greatly appreciated.
You can use the WorksheetFunction.VLookup Method for this
VariableName = Application.WorksheetFunction.VLookup("Parameter", Worksheets("Worksheet1").Range("A:B"), 2, False)
- Parameter = lookup value
we want to lookup
- Parameter = lookup range
our lookup and return data is in columns A:B of the worksheet named
- Parameter = column index (of lookup range) to return
we want to return the value of column
2of the lookup range (this is B)
- Parameter = exact match or an approximate match
Falsemeans exact match