AOB
Well-known Member
- Joined
- Dec 15, 2010
- Messages
- 669
- Office Version
- 365
- 2016
- 2013
- Platform
- Windows
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Surname
[/TD]
[TD]FirstName
[/TD]
[TD]Age
[/TD]
[/TR]
[TR]
[TD]Jones
[/TD]
[TD]Alan
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]Smith
[/TD]
[TD]John
[/TD]
[TD]35
[/TD]
[/TR]
[TR]
[TD]Murphy
[/TD]
[TD]Paul
[/TD]
[TD]42
[/TD]
[/TR]
[TR]
[TD]Jones
[/TD]
[TD]Stephen
[/TD]
[TD]99
[/TD]
[/TR]
[TR]
[TD]Walsh
[/TD]
[TD]Paul
[/TD]
[TD]21
[/TD]
[/TR]
</tbody>[/TABLE]
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 :
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 :
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?
<tbody>[TR]
[TD]Surname
[/TD]
[TD]FirstName
[/TD]
[TD]Age
[/TD]
[/TR]
[TR]
[TD]Jones
[/TD]
[TD]Alan
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]Smith
[/TD]
[TD]John
[/TD]
[TD]35
[/TD]
[/TR]
[TR]
[TD]Murphy
[/TD]
[TD]Paul
[/TD]
[TD]42
[/TD]
[/TR]
[TR]
[TD]Jones
[/TD]
[TD]Stephen
[/TD]
[TD]99
[/TD]
[/TR]
[TR]
[TD]Walsh
[/TD]
[TD]Paul
[/TD]
[TD]21
[/TD]
[/TR]
</tbody>[/TABLE]
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?