I'm trying to index match multiple criteria using VBA. I'm trying to do this to avoid using loops to speed this up on large files. I've attached a small example. Any ideas? Thank you!
VBA Code:
Option Explicit
Sub match()
Dim wb As Workbook
Set wb = Application.ThisWorkbook
Dim ws As Worksheet
Set ws = wb.Sheets("Sheet1")
Dim NewTable As Object
Set NewTable = ws.ListObjects("Table1")
Dim food As Range
Set food = NewTable.ListColumns("food").DataBodyRange
Dim product As Range
Set product = NewTable.ListColumns("product").DataBodyRange
Dim period As Range
Set period = NewTable.ListColumns("period").DataBodyRange
Dim target_period As Long
target_period = 4
Dim target_product As String
target_product = "b"
Dim yay As String
yay = Application.WorksheetFunction.Index(food, _
Application.WorksheetFunction.match(target_period & "&" & target_product, _
Application.WorksheetFunction.Index(period & product, 0), 0))
yay = Application.WorksheetFunction.Index(food, _
Application.WorksheetFunction.Index( _
Application.WorksheetFunction.match(1, (period = target_period) * (product = target_product), 0), 1))
yay = Application.WorksheetFunction.Index(NewTable, _
Application.WorksheetFunction.match(1, (period = target_period) * (product = target_product), 0))
End Sub