How do I use Index & Match to reference a separate sheet?

kminh

New Member
Joined
Nov 10, 2019
Messages
1
I have the following test code that is working where column H is equal to what's in column B versus column D


Range("H2:H17") = "=INDEX(D2:D17,MATCH(B2:B17,B2:B17,0))"




Column B Column D Column H
A Test1 Test1
B Test2 Test2
C Test 3 Test3
D Test 4 Test4
E Test 5 Test5
F Test 6 Test6
G Test 7 Test7
H Test 8 Test8
I Test 9 Test9
J Test 10 Test10




Question:




How do I use the same code to reference a seperate table called "temp" to do the same thing. The idea is for each time the code looks for 'target' it does
an index and match checking column B to equal what's in column D so if the value A is passed then it would become Test1? I tried the following code, but get error "Sub or Function not defined"
when it comes to 'Match' and the code stops.




TargetPortF = Application.WorksheetFunction.Index(Sheets("Temp").Range("D2:D17"), Match(Sheets("Temp").Range("B2:B17"), Sheets("Temp").Range("B2:B17"), 0))




Any help is appreciated!
 

Some videos you may like

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.

Worf

Well-known Member
Joined
Oct 30, 2011
Messages
4,126
Try qualifying match:

VBA Code:
b = WorksheetFunction.Index(Sheets("SI").[B2:B31], _
    WorksheetFunction.Match(a, Sheets("SI").[A2:A31], 0))
 

Watch MrExcel Video

Forum statistics

Threads
1,127,550
Messages
5,625,455
Members
416,107
Latest member
AVaes

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