[英]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. 我为此创建了以下VBA代码,尽管该代码确实将公式添加到了适当的范围,但该公式不起作用。 It's as if the Array portion is not being applied.
好像没有应用Array部分。 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. 您正在使用xlR1C1表示法,但VBA会将其读取为xlA1表示法。
MIR!C1
is not MIR!A:A
, it is first row, third column on the MIR worksheet (eg MIR!C1
). MIR!C1
不是MIR!A:A
,它是MIR工作表上的第一行,第三列(例如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. 使用xlA1表示法的公式。
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. 顺便说一句,您确实应该将MATCH中的那些完整列引用削减到使用的数据范围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.