jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
834
Hello,

The following code I have recorded as an array formula but it runs as a run-time error 1004. It is 246 characters, so under the limit of 256 - any ideas why it will not work please?

Code:
    Range("T10").FormulaArray = "=AVERAGE(IF(ROW(R2C16:R5000C16)<=SMALL(IF(ISNUMBER(R2C16:R5000C16),IF(R2C2:R5000C2=VALUE(R[-7]C[-1]),ROW(R2C16:R5000C16))),MIN(SUM(IF(R2C2:R5000C2=VALUE(R[-7]C[-1]),IF(ISNUMBER(R2C16:R5000C16),1))),5)),IF(R2C2:R5000C2=VALUE(R[-7]C[-1]),IF(ISNUMBER(R2C16:R5000C16),R2C16:R5000C16))))"
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Actually, it looks like it's 282 characters in length. So it exceeds the limit. Try the following instead...

Code:
    Dim strFormulaPart1 As String
    Dim strFormulaPart2 As String

    strFormulaPart1 = "SMALL(IF(ISNUMBER($P$2:$P$5000),IF($B$2:$B$5000=VALUE(S3),ROW($P$2:$P$5000))),Y_Y_Y)"
    strFormulaPart2 = "MIN(SUM(IF($B$2:$B$5000=VALUE(S3),IF(ISNUMBER($P$2:$P$5000),1))),5)"

    With Range("T10")
        .FormulaArray = "=AVERAGE(IF(ROW($P$2:$P$5000)<=X_X_X,IF($B$2:$B$5000=VALUE(S3),IF(ISNUMBER($P$2:$P$5000),$P$2:$P$5000))))"
        .Replace "X_X_X", strFormulaPart1
        .Replace "Y_Y_Y", strFormulaPart2
    End With

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,657
Members
449,462
Latest member
Chislobog

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