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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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.
 
Upvote 0
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
 
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,213,556
Messages
6,114,284
Members
448,562
Latest member
Flashbond

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