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
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

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!
 

Watch MrExcel Video

Forum statistics

Threads
1,118,099
Messages
5,570,207
Members
412,308
Latest member
jt145
Top