AOB
Well-known Member
- Joined
- Dec 15, 2010
- Messages
- 655
- Office Version
- 365
- 2016
- 2013
- Platform
- Windows
Surname | FirstName | Age |
Jones | Alan | 20 |
Smith | John | 35 |
Murphy | Paul | 42 |
Jones | Stephen | 99 |
Walsh | Paul | 21 |
<tbody>
</tbody>
Hi there,
Say I have a table that looks something like the above (sorry, the editor won't let me insert it in the correct position in the post)
Let's call it tblContacts
Within a sheet, I can perform a multiple criteria lookup in that table using an INDEX/MATCH array formula like so :
Code:
{=INDEX(tblContacts, MATCH(1,(tblContacts[Surname]=$B$1)*(tblContacts[FirstName]=$D$1),0),COLUMN(tblContacts[Age])-COLUMN(tblContacts))}
Nice and dynamic - even if the table expands, contracts or moves, as long as the column names remain the same, the formula will always work
What is the (best) equivalent method via a VBA function to do a multiple criteria lookup in a named table?
Á la :
Code:
Public Function GetAge(strSurname As String, strFirstName As String) As Long
Dim shtData As Worksheet
Dim lsoContacts As ListObject
Set shtData = ThisWorkbook.Sheets("Static")
Set lsoContacts = shtData.ListObjects("tblContacts")
....
End Function
Given the data is formally structured in a table, it seems this should be something very straightforward to do in VBA (like it is via the formula) but it's not obvious to me?
I mean doing it via the ListObject object directly, not via Application.WorksheetFunction or Worksheet.Evaluate
Any pointers?