[英]Variable in Array returns “Unable to set the FormulaArray property of the Range class”
I have a section in my current vba that goes through 10000 rows within an array formula and, within a table on another tab, it places cell values based on their position to a lined header...the code looks like this: 我当前的vba中有一个部分可以遍历数组公式中的10000行,并且在另一个选项卡的表中,它可以根据其位置将单元格值放置到行头中...代码如下所示:
Selection.FormulaArray = _
"=INDEX('Sheet1'!R1C1:R10000C2,SMALL(IF(ISNUMBER(SEARCH(""*__________*"",'Sheet1'!R1C1:R10000C2)),ROW('Sheet1'!R1C1:R10000C2)),ROW(R[-8]))+1,1)"
This lined header length changes between data, which is why I have to do the 'contains' vs. 'equals'. 衬里的标题长度在数据之间变化,这就是为什么我必须要做“包含”与“相等”的原因。 This is working for me, but it is taking awhile to run and I was hoping to reduce its run time.
这对我来说很有效,但是要花一些时间才能运行,我希望减少运行时间。 When I copy data into Sheet1, most of the time, it is far less than 10000 rows (but I need it that high for some data).
在大多数情况下,当我将数据复制到Sheet1时,它远远少于10000行(但是对于某些数据,我需要那么高)。 I was trying to use a variable with UsedRange, but when I put that in the array formula, I get the error in the title.
我试图在UsedRange中使用变量,但是当我将其放在数组公式中时,标题出现错误。 Here's my code with the variable:
这是带有变量的代码:
Dim LR As Long
LR = Worksheets("Sheet1").UsedRange.Rows.Count
Selection.FormulaArray = _
"=INDEX('Sheet1'!R1C1:R1C2 & LR,SMALL(IF(ISNUMBER(SEARCH(""*__________*"",'Sheet1'!R1C1:R1C2 & LR)),ROW('Sheet1'!R1C1:R1C2 & LR)),ROW(R[-8]))+1,1)"
Can anyone help me understand why I get this error? 谁能帮助我了解为什么会出现此错误? Thanks.
谢谢。
You need to take LR
outside the "
every time you was it as a reference to last row. 你需要采取
LR
外面"
你是它作为最后一行的引用每次。
Also, you just placed LR
at the end, it's needs to replace the constant "R10000C2"
with "R" & LR & "C2"
. 另外,您只是将
LR
放在最后,需要将常量"R10000C2"
替换为"R" & LR & "C2"
。
Selection.FormulaArray = _
"=INDEX('Sheet1'!R1C1:R" & LR & "C2 ,SMALL(IF(ISNUMBER(SEARCH(""*__________*"",'Sheet1'!R1C1:R" & LR & "C2)),ROW('Sheet1'!R1C1:R" & LR & "C2)),ROW(R[-8]))+1,1)"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.