简体   繁体   English

将具有动态范围的索引匹配公式转换为VBA

[英]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.

相关问题 Excel:使用公式(无 VBA)如何检查范围内的元素是否在另一个由索引/匹配定义的数组中 - Excel: Using a formula (no VBA) how to check if elements in a range are in another array which is defined by index/match 使用数组公式将具有多个条件的索引匹配转换为VBA - Index Match with multiple criteria conversion to VBA using an array formula 将 importrange 添加到索引匹配公式中,其中索引和匹配都需要导入范围 - Adding importrange to index match formula where the import range is required in both index and match 数组公式索引匹配? - Array formula index match? 在索引/匹配公式中求和 - Sum in a index/match formula Excel VBA-在匹配查找数组中引用ActiveCell.Formula中的命名范围 - Excel VBA - referring to named range in ActiveCell.Formula within match lookup array 将INDEX MATCH公式更改为EXCEL中的数组公式 - Change INDEX MATCH formula to an array formula in EXCEL 具有OR条件的索引匹配数组公式 - Index Match Array Formula with an OR condition 使用索引匹配的数组公式 - Use array formula with index match 使用 VBA,有没有办法根据两列的条件查找单元格(类似于索引匹配公式) - Using VBA, is there a way to look up a cell based on criteria for two columns (similar to Index Match formula)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM