Entering formula in A1 mode works but in R1C1 mode fails

Clif McIrvin

New Member
Joined
Dec 22, 2023
Messages
11
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
First, I apologize if this has already been addressed. I was unsuccessful at trying to find anything similar.
I have a working formula to average the bottom three values in a filtered list.
My VBA routine which builds the spreadsheet from scratch (reading data from individual files) fails in this loop:
VBA Code:
    For ix = colAvg To LastDefinedCol
        dest.Cells(NextRow, ix).FormulaR1C1 = AllHistoryFormulas(ix)
    Next ix
Where ix is the current column number, and AllHistoryFormulas() is an array of formula text.
The code fails when it reaches this formula with:
Error Number 1004
Application-defined or object-defined error
When I attempt to enter this formula in the R1C1 formula bar I get "You've entered too few arguments for this function" with the cursor at the end of the LAMBDA function:
1725037881163.png

Here's my working formula as shown in the R1C1 formula bar:
Excel Formula:
=AVERAGE(TAKE(FILTER(R16C[-4]:RC[-4],MAP(R16C[-4]:RC[-4],LAMBDA(r,--(SUBTOTAL(103,r)=1)))=1),-3))
1725038774105.png

And, the same formula in the A1 formula bar:
Excel Formula:
=AVERAGE(TAKE(FILTER(R$16:R19,MAP(R$16:R19,LAMBDA(r,--(SUBTOTAL(103,r)=1)))=1),-3))
1725038820312.png

1725038845525.png

Clear as mud?
What am I doing wrong?
I'm using .FormulaR1C1 because the formula text does not change with the cell address.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Interesting. I disabled error checking, and I get the expected result!
That is, I changed that loop to
VBA Code:
    On Error Resume Next
    For ix = colAvg To LastDefinedCol
        dest.Cells(NextRow, ix).FormulaR1C1 = AllHistoryFormulas(ix)
    Next ix
    On Error GoTo 0
 
Upvote 0
Interesting. I disabled error checking, and I get the expected result!
I spoke too soon. Finding the formula in the cell with disabled error handling must have been a fluke - perhaps I had manually copied the formula into that cell before running the code.
I just ran the code several times in the process of verifying other parts of the code, and now I'm getting what I expected with the disabled error handling: the loop completes and leaves this particular cell empty.
 
Upvote 0
The use of "r" as a variable seems to be confusing it. I changed r to rng and it appears to have fixed it.
Rich (BB code):
=AVERAGE(TAKE(FILTER(R16C[-4]:RC[-4],MAP(R16C[-4]:RC[-4],LAMBDA(rng,--(SUBTOTAL(103,rng)=1)))=1),-3))
 
Upvote 0
Solution

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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