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
 

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!
 

Forum statistics

Threads
1,081,841
Messages
5,361,630
Members
400,642
Latest member
tekster23

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top