VBA: Using 2 variables with Match

rbsam

New Member
Joined
Jul 12, 2019
Messages
42
Code:
[COLOR=#000000][FONT='inherit']ws2.Range("D3").Value = Application.WorksheetFunction.Match(variable_i, ws2.Range("A:A"), 0)[/FONT][/COLOR]

ws1 = worksheet 1 ws2 = worksheet 2

  • On ws1 I have 2 columns of drop down boxes (data validation list)
  • the selection from the first column of drop down boxes is assigned to the variable "variable_i"
  • the selection from the second column of drop down boxes is assigned to the variable "variable_p"
  • It pulls its data from ws2 (the range is all of column a)
  • It is looking for the selection from the drop down box with the variable "variable_i"... the code works fine, it returns the number row on D3 without any issues
  • I'm looking for it to return the row number that contains both variables in the 2 columns (variable_i and variable_p)
I've tried the following code:

Code:
[COLOR=#000000][FONT='inherit']ws2.Range("D3").Value = Application.WorksheetFunction.Match(variable_i & variable_p, ws2.Range("A:B"), 0)[/FONT][/COLOR]


as I had seen that online, but it doesn't work for me.
The error I get is: "Run-time error '1004': Method 'Match' of object 'WorksheetFunction' failed
What would be the best way to have multiple variables be the lookup?

I've read I need to use Evaluate but I can't get my head around how it works

Any help would be much appreciated!

 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Not sure how to delete this thread but I worked out that where the variables are you need 3x """ and a & either side of it for it to recognise that it's a VBA variable
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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