简体   繁体   English

在Excel VBA ROW(1:1)中引用索引公式数组中的字符串

[英]Referencing a string within an Index Formula Array in Excel VBA ROW(1:1)

Need some help referencing a string in an Index formula array 需要一些帮助引用索引公式数组中的字符串

My code below: 我的代码如下:

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

I am trying to put a reference in this part: 我试图在这部分中提供参考:

ROW(1:1)

change it to: 更改为:

ROW(""" & R & """ : """ & R & """)

However receiving an object error 1004 但是收到对象错误1004

Delete double quotes 删除双引号

ROW(" & R & " : " & R & ")

Full: 充分:

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)"

Example to understand: 示例了解:

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

?b in immediate window (Ctrl+G) will print: 立即窗口(Ctrl + G)中的?b将打印:

sometext_10_sometext sometext_10_sometext

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

will print: 将打印:

sometext_"10"_sometext sometext_“ 10” _sometext

Double quotes in editor goes as quote in variable. 编辑器中的双引号与变量中的引号一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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