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:
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). 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. 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.