Search for text in name range in Sheet 1and return Value in Sheet 2 using Excel VBA
Question
I have something of the following :
Sheet 1
(Name Range : Code)
Column A -------- Column B
School ------------ 1
College ----------- 2
University--------- 3
Sheet 2
Cell A1 = (Search for "College" in Name Range Code and get the Value of "2" as code. ) So value of 2 should be present in Cell A1.
Please provide excel VBA
Solution
This works for me:
Sub LookUpValue()
Dim searchValue As String
Dim lookupTable As Range
Set lookupTable = Worksheets("Sheet1").Range("Code")
searchValue = "College"
Worksheets("Sheet2").Range("A1") = WorksheetFunction.VLookup(searchValue, lookupTable, 2, False)
End Sub
Hope this helps...
OTHER TIPS
Use the VLOOKUP
function.
Which is Application.WorksheetFunction.VLookUp
in VBA.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow