insomniac53
Board Regular
- Joined
- Sep 3, 2013
- Messages
- 104
I have a series of tables on a worksheet, indentical in layout, and I need a VBA function to use a LOOKUP function for any of the tables sent to it. Simplified, the tables look like this:
<tbody>
[TD="class: xl65"]Table1[/TD]
[TD="class: xl65"][/TD]
[TD="class: xl65"][/TD]
[TD="class: xl65"]Table2[/TD]
[TD="class: xl65"][/TD]
[TD="class: xl65, width: 38"][/TD]
[TD="class: xl72"]id[/TD]
[TD="class: xl73"]col1[/TD]
[TD="class: xl74"]col2[/TD]
[TD="class: xl72"]id[/TD]
[TD="class: xl73"]col1[/TD]
[TD="class: xl74"]col2[/TD]
[TD="class: xl66"]1[/TD]
[TD="class: xl67"]a[/TD]
[TD="class: xl68"]d[/TD]
[TD="class: xl66"]1[/TD]
[TD="class: xl67"]u[/TD]
[TD="class: xl68"]x[/TD]
[TD="class: xl66"]2[/TD]
[TD="class: xl67"]b[/TD]
[TD="class: xl68"]e[/TD]
[TD="class: xl66"]2[/TD]
[TD="class: xl67"]v[/TD]
[TD="class: xl68"]y[/TD]
[TD="class: xl69"]3[/TD]
[TD="class: xl70"]c[/TD]
[TD="class: xl71"]f[/TD]
[TD="class: xl69"]3[/TD]
[TD="class: xl70"]w[/TD]
[TD="class: xl71"]z[/TD]
</tbody>
My function needs to look up the number passed to the function in the id column of the given table and return data from col1 or col2 in the appropriate table. This is where I am so far:
So, if the function was sent 3, "Table2", 2 - it would return "w"
Hope that makes sense and someone can help. Thank you.
<tbody>
[TD="class: xl65"]Table1[/TD]
[TD="class: xl65"][/TD]
[TD="class: xl65"][/TD]
[TD="class: xl65"]Table2[/TD]
[TD="class: xl65"][/TD]
[TD="class: xl65, width: 38"][/TD]
[TD="class: xl72"]id[/TD]
[TD="class: xl73"]col1[/TD]
[TD="class: xl74"]col2[/TD]
[TD="class: xl72"]id[/TD]
[TD="class: xl73"]col1[/TD]
[TD="class: xl74"]col2[/TD]
[TD="class: xl66"]1[/TD]
[TD="class: xl67"]a[/TD]
[TD="class: xl68"]d[/TD]
[TD="class: xl66"]1[/TD]
[TD="class: xl67"]u[/TD]
[TD="class: xl68"]x[/TD]
[TD="class: xl66"]2[/TD]
[TD="class: xl67"]b[/TD]
[TD="class: xl68"]e[/TD]
[TD="class: xl66"]2[/TD]
[TD="class: xl67"]v[/TD]
[TD="class: xl68"]y[/TD]
[TD="class: xl69"]3[/TD]
[TD="class: xl70"]c[/TD]
[TD="class: xl71"]f[/TD]
[TD="class: xl69"]3[/TD]
[TD="class: xl70"]w[/TD]
[TD="class: xl71"]z[/TD]
</tbody>
My function needs to look up the number passed to the function in the id column of the given table and return data from col1 or col2 in the appropriate table. This is where I am so far:
Code:
Function TestLookup(i As Integer, s As String, j as integer)
'i is the data in column 1, s is the table name, j needs to be 1 or 2 or whichever column I want returned.
Dim w1 As Worksheet: 'then I set the worksheet name
TestLookup = Application.WorksheetFunction.VLookup(i, w1.ListObjects(s).... ' and I'm stuck!!
End Function
So, if the function was sent 3, "Table2", 2 - it would return "w"
Hope that makes sense and someone can help. Thank you.