Simple Excel VBA Help

Soldato
Joined
18 Oct 2002
Posts
7,492
Location
Maidenhead
Having a mind block. I need some code to search column A for a specific string and return the value of the cell to the right of it ie

String = test

test is in cell A5 - I need the value of cell B5.

Thanks
 
Soldato
Joined
18 Oct 2002
Posts
5,226
Location
Overground, underground..
It can be done using built in functions - INDEX & MATCH

Define column A as a range, call it 'one'

Define column B as a range, call it 'two'

Value you want = INDEX(two,MATCH("search string",one,0))
 
Permabanned
Joined
18 Oct 2002
Posts
2,275
One way of solving this is using the range function. I'm not going to write the solution for you because I haven't got time although here is some code I use in work:-

For iLoop = Asc("B") To Asc("L") '******* Step through each column (09:00, 10:00, 11:00, etc)*****
StartRow = 3 '******* The start row in the Excel worksheet *******************
EndRow = 20 '******* The end row in the Excel worksheet *********************
Do While StartRow < EndRow + 1
SearchTable Range(Chr(iLoop) & StartRow).Value, StartTime
StartRow = StartRow + 1
Loop
StartTime = DateAdd("h", 1, StartTime)
Next

I hope this gives you an idea. Try searching on Google for "range excel VBA" or something to that effect.
 
Back
Top Bottom