Question : Using highlighted field for vlbookup in Excel 2007

If I have seven values on an excel spreadsheet:  A7:A13       Is there a way to use vblookup relative to which field is highlighted on the spreadsheet?  For example if the cursor is on A8, this is the value I would like to use for my lookup.

Answer : Using highlighted field for vlbookup in Excel 2007

Yes, you have to do it with VBA.  Here's is one option:

Put this in the Sheet module that you want to use vlookup in:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   Range("D1").Value = ActiveCell.Address
End Sub

Then use this as the vlookup formula:
=VLOOKUP(INDIRECT(D1),test,2,FALSE)

Where test is your range, and Indirect(D1) is the value that is set to the ActiveCell from the code above.

See attached working example.

 
Example
 
Random Solutions  
 
programming4us programming4us