簡體   English   中英

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

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

需要一些幫助引用索引公式數組中的字符串

我的代碼如下:

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)中的?b將打印:

sometext_10_sometext

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

將打印:

sometext_“ 10” _sometext

編輯器中的雙引號與變量中的引號一樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM