Using Match in VBA to find the row number based on multiple criteria

BBxcl

New Member
Joined
Sep 29, 2021
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hi,

I’m working on a table in Excel VBA and I want to assign the row number of the cell that meets multiple criteria to a variable.

Normally, using Excel’s Match function, I would do something like =MATCH(1, (criteria logic 1)*(criteria logic 2), 0)

However when I try to do this in excel VBA using Evaluate, I get a type mismatch error. The following is a snippet of my VBA code:

VBA Code:
Dim tbl As ListObject
Dim result_rw As Variant
Dim match_Formula As String

Set tbl = Sheet1.ListObjects("Table_1")

match_Formula = "MATCH(1,(" & """ & tbl.DataBodyRange(rw,3) & """ & "=" & """ & tbl.ListColumns(3).DataBodyRange & """ & ")*(" & """ & tbl.ListColumns(10).DataBodyRange & """ & "=1), 0)"
result_rw = Evaluate(match_Formula)

Where the variable rw has been calculated through previous calculations and stores the value of the row number of the data that I am comparing to.

The type mismatch error occurs when I try to assign the String to match_Formula variable and I suppose this is happening because I am trying to store a Range inside a String variable. However, I have to perform my comparison against the whole column range so I'm not sure what other way there is around this.

Can anyone please help with this?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You might find it worth while looking at this thread where I helped somebody with an index/match problem which i solved using the dictionary object which can be much faster than using index match.I don't understand what you are trying to do so , I can't help with specific code at this time:
Speed up excel file (maybe VBA?)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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