Reputation: 119
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.
Upvotes: 1
Views: 2594
Reputation: 57683
You can use the WorksheetFunction.VLookup Method for this
VariableName = Application.WorksheetFunction.VLookup("Parameter", Worksheets("Worksheet1").Range("A:B"), 2, False)
"Parameter"
Worksheet1
2
of the lookup range (this is B)False
means exact matchUpvotes: 2