在Excel VBA行(1:1)中引用索引公式数组中的string

在索引公式数组中需要一些引用string的帮助

我的代码如下:

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

删除双引号

 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" 

在即时窗口中(Ctrl + G)将会打印:

sometext_10_sometext

 b = "sometext_""" & a & """_sometext" 

将打印:

sometext_ “10” _sometext

编辑器中的双引号在variables中作为引号。