How do I use listobjects for Index/Match in VBA?

rizzo93

Active Member
Joined
Jan 22, 2015
Messages
303
Office Version
  1. 365
I'm want to use tables and column names when using index/match with vba. I can get my formula to work when I enter a fixed range like this:

VBA Code:
Sub NotAckMe()
Dim sourceTbl, apolloProcessed As ListObject
Dim apollo As Worksheet
Dim sourceRows As Integer
Dim estimator, b As String

    Set apollo = Worksheets("Apollo Processed")
    Set apolloProcessed = apollo.ListObjects("q_ApolloProcessed")
    Set sourceTbl = mySource.ListObjects("tblNotAcknowledged")
    sourceRows = sourceTbl.DataBodyRange.Rows.Count

    For r = 5 To sourceRows + 4
        estimator = mySource.Cells(r, 2)
        b = Application.WorksheetFunction.Index(apollo.Range("G3:G121"), Application.WorksheetFunction.Match(estimator, apollo.Range("B3:B121"), 0))
    Next r

End Sub

But what I want to do is replace the ranges above (in the For loop) to reference the columns within my table (apolloProcessed).

What am I missing, please?
 
It should be
VBA Code:
Dim sourceTbl As ListObject
singular rather than plural.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
It should be
VBA Code:
Dim sourceTbl As ListObject
singular rather than plural.
Interesting. Ok, so singular when declaring it, but plural when you are assigning a variable to a table. It worked though. ;)

With that in mind, I'll go back to the code we worked with yesterday and see if there's any discrepancy in that regard.
 
Upvote 0
Ok, so singular when declaring it, but plural when you are assigning a variable to a table.
That's right you are assigning a single table (listobject) from the collection of all tables (listobjects )
 
Upvote 0
That's right you are assigning a single table (listobject) from the collection of all tables (listobjects )
I figured out what the problem was. I had the rngReturn and rngMatch referring to the wrong columns. Once I made the switch, it worked out.

Fluff, I REALLY appreciate your help. Thank you very much!
 
Upvote 0
Solution
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top