Solved

# Lookup table

Posted on 2004-03-25
514 Views
I need to retrieve an element from a cell block but cannot get it right.

I have the following on an EXCEL worksheet

V7      P7      W7      P4      L7
AES      ZZA      MMG      IVB      MMA
IID      ZZB      MMH      IVF      MMB
IIG      ZZC      MMI      IVI      MMC
IIJ            MMJ      IVM      MMD
IIK            MMK      IVO      MME
IIN            MML      IVR      MMF
IIS            MMM      IVS
IIT            MMN      IVW
IIU            MMO      IVX
IIV            MMP      IVY
IIW                  IVZ
IIX                  NLE
IIY                  NLF
NLK
NLN
NLO
NLP
NLS
NLT
NLV
NLW
NLX
NLY
NLZ
YGB
YGE

The data being supplied is one of the values AES, IVX etc. etc. and what I want is the value at the top of the appropriarte column (ie one of P4, W7, P7 etc.)
How do I use the appropriate lookup and reference functions to extract the value at the top of the column, given the value supplied.
Note that the number of values in each column is not constant and that the values are not in sorted order, although this could be done if it makes the solution easier.

Big points available for the first person to get it right
0
Question by:GSD4ME

LVL 15

Expert Comment

ID: 10680112
I don't know excel well enough to provide the solution, but I can give you a quick logic approach that you can try.

Find the item that you are looking for.  I would guess that Excel provides a find function that returns a cell.

When you know the cell that you are in then you need to look in the first row of the same colum to get it's value.

Of course what I'm saying may be what you already know.
0

LVL 5

Assisted Solution

g0rath earned 250 total points
ID: 10680562
Dim SearchRange as Excel.Range
Dim FoundCell as Excel.Range

Set SearchRange = ThisWorkbook.Worksheet("Sheet1").UsedRange
Set FoundCell = SearchRange.Find("Hello")

Then you can do stuff like

Set FoundCell = SearchRange.FindNext

etc etc...

0

LVL 1

Accepted Solution

ID: 10681833
In addition to g0rath you can do like that. Put this code in a macro and call. You need to call everytime for each supplied value. Hope this helps you more.

Dim SearchRange As Excel.Range
Dim FoundCell As Excel.Range
Dim SuppliedValue As String

SuppliedValue = InputBox("Enter Cell Value to Find")
Set SearchRange = ThisWorkbook.Worksheets("Sheet1").UsedRange
Set FoundCell = SearchRange.Find(SuppliedValue)

'MsgBox FoundCell.Column
MsgBox FoundCell.EntireColumn.Cells(1, 1).Value

FoundCell.EntireColumn.Cells(1, 1).Activate
0

Author Comment

ID: 10688981
Thanks to the pair of you for the answer - exactly what I wanted.
Points have been split evenly
0

## Featured Post

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…