| | |
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:
Solved Threads: 9
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?
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?
•
•
Join Date: Apr 2008
Posts: 58
Reputation:
Solved Threads: 9
Okay, I came up the following code which finds the cell address of the lookup (z) data.
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!
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Sub lookup() Dim lookup lookup = Range("lookup").Value For each c in Range("lookup_range").Cells If (c.Value = lookup) Then Range("lookup_return").Value = c.Address Exit Sub End If Next 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!
![]() |
Similar Threads
- Trojan.Cachecachekit (Viruses, Spyware and other Nasties)
- VBA - Excel - sheet,range lookup with variables (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: vb6 moving frameless form on screen
- Next Thread: Excel cell references
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





