R1C1 notation not working in VBA formula

canyon

New Member
Joined
Jan 5, 2022
Messages
24
Office Version
  1. 2019
Platform
  1. Windows
I have the following formula I copied from using the macro recorder. The issue is that it seems to remain an absolute value instead of relative. Where RC[-5] should be D2 and then the next cell D3, D4... etc. When I substitute the R[-5] for D2 the formula doesn't work.

Is this because its an array formula?

VBA Code:
For Each cell In RNG

range(Cells(2, 9), Cells(LastRow, 9)).FormulaArray = _
        "=INDEX('[filename.xlsx]sheetname'!C2,MATCH(""3730""&RC[-5],'[filename.xlsx]sheetname'!C1&'[filename.xlsx]sheetname'!C5,0))"


    
    
    
Next cell

End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You need to enter the formula into one cell, then fill it down.
 
Upvote 0
You need to enter the formula into one cell, then fill it down.

You need to enter the formula into one cell, then fill it down.
Interesting. Array formulas are new to me so I was not aware.

VBA Code:
Dim LastRow As Long

LastRow = Cells(Rows.Count, "C").End(xlUp).Row

range(Cells(2, 9), Cells(LastRow, 9)).FormulaArray = _
        "=INDEX('[filename.xlsx]sheetname'!C2,MATCH(""3730""&RC[-5],'[filename.xlsx]sheetname'!C1&'[filename.xlsx]sheetname'!C5,0))"
        
range("I2").AutoFill Destination:=range(Cells(2, 9), Cells(LastRow, 9)), Type:=xlFillDefault

I've included my autofill code but it seems to still do the same thing.
 
Upvote 0
You're still populating the entire range with the formula initially. This part:

Code:
range(Cells(2, 9), Cells(LastRow, 9)).FormulaArray

should be:

Code:
Cells(2, 9).FormulaArray
 
Upvote 0
You're still populating the entire range with the formula initially. This part:

Code:
range(Cells(2, 9), Cells(LastRow, 9)).FormulaArray

should be:

Code:
Cells(2, 9).FormulaArray
Thank you very much!
 
Upvote 0
You're still populating the entire range with the formula initially. This part:

Code:
range(Cells(2, 9), Cells(LastRow, 9)).FormulaArray

should be:

Code:
Cells(2, 9).FormulaArray
Hi,

I keep getting this error and am unsure what its impacting:

"Unable to set the FormulaArray property of the Range class"

VBA Code:
Dim LastRow As Long
LastRow = Cells(Rows.Count, "C").End(xlUp).Row

Cells(2, 9).FormulaArray = _
        "=(INDEX('[filename.xlsx]sheet'!$B:$B,MATCH(""3730""&RC[-5],'[filename.xlsx]sheet'!$A:$A&'[filename.xlsx]sheet'!$E:$E,0))"
range("I2").AutoFill Destination:=range(Cells(2, 9), Cells(LastRow, 9)), Type:=xlFillDefault
 
Upvote 0
How long is the actual formula you are using? FormulaArray is limited to 255 characters.
 
Upvote 0
How long is the actual formula you are using? FormulaArray is limited to 255 characters.
That could do it, I replaced the actual workbook and sheets on here with place holders. I've done the same in my VBA code now, getting 194 characters...

VBA Code:
Cells(2, 9).FormulaArray = "=INDEX('[" & filepath & "]" & sheetname & "'!$B:$B,MATCH(""3730""&RC[-5],'[" & filepath & "]" & sheetname & "'!$A:$A&'[" & filepath & "]" & sheetname & "'!$E:$E,0))"
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top