Excel VBA or Lookup Help

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Apr 2008
Posts: 58
Reputation: omrsafetyo is an unknown quantity at this point 
Solved Threads: 9
omrsafetyo omrsafetyo is offline Offline
Junior Poster in Training

Excel VBA or Lookup Help

 
0
  #1
Jan 23rd, 2009
Unfortunately, I don't think this question is solved with a simple vlookup, or etc.

I have a spreadsheet that has several tables of data with the following format on one sheet:

gxxxx
gxxxx
gxxxx
zzzzz


gxxxx
gxxxx
gxxxx
zzzzz

The "g"s above would indicate an item for lookup. The "z"s would be another lookup reference. The "x" fields will always be a numeric value.

I have a field that defines a lookup value which is associated with the "z" data. Each of these tables are defined as one named range and I can't be sure ahead of time which table the lookup value will be found in.

What I would like to do is as follows:
1. Have the value "z" be located in my tables
2. Identify any values "x" in the column above the "z" value that are non-zero.
3. Return the corresponding value "g" for this lookup.

What I'm guessing needs to be accomplished is to somehow identify the column and row of the lookup on z. My tables are each a defined length, so I can then return a sub-range based on this lookup. So, e.g. if the value is found to be in B200, I could define my range as B141:B200.

I can then scan this range for any values that are non-zero - for each one, I would probably want to assign the value of the cell to one variable (dim value); identify the row that the value is in (dim row), and then return the corresponding value from column A ("A" & row) into a variable (dim item). I would then populate two fields with the values from row and item and move on to the next non-zero "x" and return the x and corresponding "g".

Does anyone have any ideas on just how to accomplish this?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 58
Reputation: omrsafetyo is an unknown quantity at this point 
Solved Threads: 9
omrsafetyo omrsafetyo is offline Offline
Junior Poster in Training

Re: Excel VBA or Lookup Help

 
0
  #2
Jan 23rd, 2009
Okay, I came up the following code which finds the cell address of the lookup (z) data.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Sub lookup()
  2. Dim lookup
  3. lookup = Range("lookup").Value
  4. For each c in Range("lookup_range").Cells
  5. If (c.Value = lookup) Then
  6. Range("lookup_return").Value = c.Address
  7. Exit Sub
  8. End If
  9. Next
  10. End Sub

For now I return the address to a placeholder cell.
This returns a value of, e.g. $A$67. I can also return just the row or column with c.Column, c.Row.

Moving on to the next part - but help is still appreciated. Thanks!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 58
Reputation: omrsafetyo is an unknown quantity at this point 
Solved Threads: 9
omrsafetyo omrsafetyo is offline Offline
Junior Poster in Training

Re: Excel VBA or Lookup Help

 
0
  #3
Jan 26th, 2009
I have this all figured out now.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC