I want to retrieve the value in column B, which corresponds with text in column A. For example I might look for the keyword "DBServerName" in column A and retrieve "Oracle_Server_1" from column B. Currently I am using a for/next loop, with a compare in each itteration, and it works fine. Is there a better way, like a Vlookup for VBA?
Just wondering. Thanks.
Finding a value
-
- Microsoft MVP
- Posts: 656
- Joined: 24 Jan 2010, 17:51
- Status: Microsoft MVP
- Location: Weert, The Netherlands
Re: Finding a value
Application.WorksheetFunction.vlookup perhaps?
-
- Administrator
- Posts: 78608
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Finding a value
To expand on Jan Karel's reply:
Code: Select all
Dim strKeyword As String
Dim strResult As String
Dim rngRange As Range
strKeyword = "DBServerName"
Set rngRange = ActiveSheet.Range("A:B")
strResult = Application.WorksheetFunction.VLookup(strKeyWord, rngRange, 2, False)
Best wishes,
Hans
Hans