VBA to add index/match with references to currently active sheet rather than absolute reference

Bert_Withpeterson

New Member
Joined
Aug 14, 2018
Messages
8
Hi everybody,

I have the below index/match formula which works in looking up values from worksheet2 that are on worksheet1 and returning a final match. Problem is I'm looking to add this to some VBA which will create a large number of worksheets, so I need the formula to calculate based on, for example worksheet3 when on worksheet3, worksheet 4 when on worksheet4 etc. Can anyone help with amending the below so that where it says 'worksheet2' it actually points to whatever the current worksheet is?

Also can anyone please advise how to code VBA to automate the process of CTRL_ALT_ENTER required to make these formulae work? Thank you!

=INDEX('Worksheet1'!O:O,MATCH(1,('Worksheet2'!B1='Worksheet1'!B:B)*('Worksheet2'!B2='Worksheet1'!C:C)*('Worksheet2'!B3='Worksheet1'!N:N)*('Worksheet2'!A13='Worksheet1'!G:G),0))
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi Bert,

In your VBA simply replace every occurrence of Worksheet2 with Active Sheet's Name (& .Name & syntax). See below (the result of this function will be displayed in the first sheet, cell A1):

Code:
Sub IndexMatch()


    With ActiveSheet
        [COLOR=#0000ff]Sheet1.Range("A1").FormulaArray[/COLOR] = _
            "=INDEX('Worksheet1'!O:O,MATCH(1,('"[COLOR=#ff0000]& .Name &[/COLOR]"'!B1='Worksheet1'!B:B)*('"[COLOR=#ff0000]& .Name &[/COLOR]"'!B2='Worksheet1'!C:C)*('"[COLOR=#ff0000]& .Name &[/COLOR]"'!B3=' Worksheet1'!N:N)*('"[COLOR=#ff0000]& .Name &[/COLOR]"'!A13='Worksheet1'!G:G),0))"
    End With


End Sub

I also assumed that you meant Ctrl+Shift+Enter (not Ctrl+Alt+Enter), so I used .FormulaArray property.

Let me know if that works.

Best regards,
Justyna
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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