简体   繁体   中英

Converting Index Match Formula with Dynamic Range to VBA

My Original formula is as follows:

=INDEX(MIR!$A:$A,MATCH(1,(MIR!$H:$H=TRI!$W2)*(MIR!$I:$I=TRI!$L2),0))

I created the following VBA Code for this and while the code does add the formula to the appropriate range, the formula does NOT work. It's as if the Array portion is not being applied. I've looked everywhere to figure this out but I obviously am not looking in the right spot. Please advise.

Range("B2").Select
Selection.FormulaArray = _
    "=INDEX(MIR!C1,MATCH(1,(MIR!C8=TRI!RC23)*(MIR!C9=TRI!RC12),0))"
Range("B2", "B" & Cells(Rows.Count, 1).End(xlUp).Row).FillDown
End Sub

You are using xlR1C1 notation but VBA is reading it as xlA1 notation. MIR!C1 is not MIR!A:A , it is first row, third column on the MIR worksheet (eg MIR!C1 ). The formula is put on the worksheet as,

=INDEX(MIR!C1,MATCH(1,(MIR!C8=TRI!RC23)*(MIR!C9=TRI!RC12),0))

Use a formula in xlA1 notation.

Range("B2").FormulaArray = "=INDEX(MIR!$A:$A,MATCH(1,(MIR!$H:$H=TRI!$W2)*(MIR!$I:$I=TRI!$L2),0))"

Btw, you should really cut those full column references in the MATCH down to the used data range.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM