需要一些帮助引用索引公式数组
中的字符串我的代码如下:
Sub Loop_Test2()
Dim i As Long
Dim j As Long
Dim CountAll As Long
Dim CountXL As Long
Dim CustomerName As String
ActiveSheet.Range("A1").Activate
CountAll = ActiveSheet.Range("A35")
For j = 1 To CountAll
i = 2
CountXL = Cells(i, j).Value
R = 1
For i = 1 To CountXL
CustomerName = Cells(1, j).Value
'MsgBox CustomerName
MsgBox R
Cells(i + 2, j).FormulaArray = "=IFERROR(INDEX(Sheet2!$A:$B,SMALL(IF(Sheet2!$A:$A=""" & CustomerName & """,ROW(Sheet2!$A:$A)),ROW(R:R))*1,2),0)"
R = R + 1
Next i
Next j
End Sub
我试图在这一部分提出一个参考:
ROW(1:1)
将其更改为:
ROW(""" & R & """ : """ & R & """)
但是收到对象错误1004
答案 0 :(得分:1)
删除双引号
ROW(" & R & " : " & R & ")
全:
Cells(i + 2, j).FormulaArray = "=IFERROR(INDEX(Sheet2!$A:$B,SMALL(IF(Sheet2!$A:$A=""" & CustomerName & """,ROW(Sheet2!$A:$A)),ROW(" & R & ":" & R & "))*1,2),0)"
要了解的示例:
a = 10
b = "sometext_" & a & "_sometext"
立即窗口中的?b(Ctrl + G)将打印:
sometext_10_sometext
b = "sometext_""" & a & """_sometext"
将打印:
sometext_ “10” _sometext
编辑器中的双引号用作变量中的引号。