Translate INDEX/MATCH code from Cell to VBA in excel

cristopulo

New Member
Joined
Aug 12, 2015
Messages
14
Hello,

I have an Index/ Match code that basically cross references values in a table to give a numerical output and need help translating it into VBA.

Here is the original code:

=INDEX(T2:AH14;MATCH(B7;S2:S14;0);MATCH(B15;T1:AH1;-1))

Range of Outputs is T2:AH14
Table Header/ Column is T1:AH1 & S2:S14
Cell References are to match with B7 & B15
and -1 specifies the greater value if not exact

This is what Ive got on VBA but im afraid its totally off.

Range("E8"). test=Application.WorksheetFunction.INDEX(Range("T2:AH14"),Application.WorksheetFunction.MATCH("B7",Range("S2:S14"),0),Application.WorksheetFunction.MATCH("B15",Range("T1:AH1"),-1,1)

Thanks in Advance
-Chris
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try:

Code:
Sub Indx_Match()
Range("E8").Formula = "=INDEX(T2:AH14,MATCH(B7,S2:S14,0),MATCH(B15,T1:AH1,-1))"
End Sub

Howard
 
Upvote 0
Yes,

Worked Perfectly. Wish I had though of inputting it directly as a formula! haha

Thank You
-Chris

You're welcome.

To add, should your formula have " " or "" in it you will need to double them up as in the example here.

If on the sheet it looks like this:

Code:
=IF(F7="W",100,"")

Then in the macro it would look like this:

Code:
Sub Watch_The_Quotes()

Range("E9").Formula = "=IF(F7=""W"",100,"""")"

End Sub

Where the quotes that Hold the formula will remain a single " at each end.

Howard
 
Upvote 0

Forum statistics

Threads
1,215,165
Messages
6,123,387
Members
449,098
Latest member
ArturS75

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