How to define joined lookup range in VBA?

nicholasho

New Member
Joined
Oct 10, 2005
Messages
6
Hi,

I am trying to perform multiple-column lookup in a table in VBA. I have successfully used & operator to achieve that in inputing similar formular in a sheet. However, I can't get it right in converting it to statements in VBA.

Set RangeOne = Worksheets("Sheet5").Range("$AX$2:$AX$2053")

Agreement = Application.WorksheetFunction.Index(RangeOne, Application.WorksheetFunction.Match(CurrOrder & CurrPart, Worksheets("Sheet5").Range("A2:A2503") & Worksheets("Sheet5").Range("K2:K2503") , 0))

I got "Run time error 13, type mismatch".

Thanks
Nick
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Tazguy37

MrExcel MVP
Joined
May 28, 2004
Messages
4,237
What's the formula look like if you enter it in the worksheet? You might try using an R1C1 formula instead. Give us some sample data, and I'm sure we can find you a solution.
 

nicholasho

New Member
Joined
Oct 10, 2005
Messages
6
Here is the formula used before writing the macro. It works to retrieve the data I want.


=INDEX('Sheet5'!$AX$2:$AX$2053,MATCH(Sheet4!F4&Sheet4!H4,'Sheet5'!$A$2:$A$2053&'Sheet5'!$K$2:$K$2053,0))


Thanks
Nick
 

Tazguy37

MrExcel MVP
Joined
May 28, 2004
Messages
4,237
And where does that formula get entered?

If it gets copied to other cells, especially in a range across a row, or down a column, an R1C1 formula might be just what you need. But, for that to work, you need to know where the formula is entered. That way, you can enter references in the formula relative to where the formula is (two columns to the right, and three rows down, for example).

You could always do something like:
Code:
Range("A1").Formula = "=INDEX('Sheet5'!$AX$2:$AX$2053,MATCH(Sheet4!F4&Sheet4!H4,'Sheet5'!$A$2:$A$2053&'Sheet5'!$K$2:$K$2053,0))"

Hope that helps!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,546
Messages
5,838,021
Members
430,526
Latest member
NiceGuyWithExcel2007

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
Top