1

I recorded the array formula in order to put in VBA. Here is what I have after the recording. However, when I run the Macro, it just doesn't work.

Will it be because of the negative sign?

From Macro

Range("D3").FormulaArray = "=IFERROR(INDEX('RMS 
Maint'!R1C[-2]:R3542C[-2],SMALL(IF(('RMS Maint'!R2C27:R3542C27=R1C2)*('RMS 
Maint'!R2C13:R3542C13=R2C4)*('RMS Maint'!R2C21:R3542C21=""Late"")*ROW('RMS 
Maint'!R2C1:R3542C1)=0,"""",('RMS Maint'!R2C27:R3542C27=R1C2)*('RMS 
Maint'!R2C13:R3542C13=R2C4)*('RMS Maint'!R2C21:R3542C21=""Late"")*ROW('RMS 
Maint'!R2C1:R3542C1)),ROW('RMS Maint'!R[-2]:R[3538])),1),"""")"

From Excel formula

=IFERROR(INDEX('RMS Maint'!C$1:C$3542,SMALL(IF(('RMS 
Maint'!$AA$2:$AA$3542=$B$1)*('RMS Maint'!$M$2:$M$3542=$D$2)*('RMS 
Maint'!$U$2:$U$3542="Late")*ROW('RMS Maint'!$A$2:$A$3542)=0,"",('RMS 
Maint'!$AA$2:$AA$3542=$B$1)*('RMS Maint'!$M$2:$M$3542=$D$2)*('RMS 
Maint'!$U$2:$U$3542="Late")*ROW('RMS Maint'!$A$2:$A$3542)),ROW('RMS 
Maint'!1:3541)),1),"")

The error is 1004 - Unable to set the FormulaArray property of the Range class

I'm sorry for the code format. It looked terrible.

2
  • 2
    The limit of a formula array insert is 255 characters with VBA Commented Apr 25, 2018 at 20:28
  • which means I would need to create ranges for the cells.Thank you! May I ask where you got that info. I want to check it out. Commented Apr 25, 2018 at 20:39

2 Answers 2

2

Or you may break the long formula into few parts and replace it in the end with the actual formula like below...

Dim LogicalTest As String, FalseValue As String

LogicalTest = "('RMS Maint'!$AA$2:$AA$3542=$B$1)*('RMS Maint'!$M$2:$M$3542=$D$2)*('RMS Maint'!$U$2:$U$3542=""Late"")*ROW('RMS Maint'!$A$2:$A$3542)=0"
FalseValue = "('RMS Maint'!$AA$2:$AA$3542=$B$1)*('RMS Maint'!$M$2:$M$3542=$D$2)*('RMS Maint'!$U$2:$U$3542=""Late"")*ROW('RMS Maint'!$A$2:$A$3542)"

Range("D3").FormulaArray = "=IFERROR(INDEX('RMS Maint'!C$1:C$3542,SMALL(IF(""LogicalTest"","""",""FalseValue""),ROW('RMS Maint'!1:3541)),1),"""")"

Range("D3").Replace """LogicalTest""", LogicalTest, LookAt:=xlPart
Range("D3").Replace """FalseValue""", FalseValue, LookAt:=xlPart
Sign up to request clarification or add additional context in comments.

2 Comments

That's another elegant way to do that! Awesome
@OliverBird Thanks! Any automation is incomplete if you are forced to ask the user to take some manual actions. So to me, actually it doesn't make any sense entering the formula as a regular formula and then ask the user to reenter it as an Array Formula. :)
1

There is an option of last resort: Use a human.

Have the macro place the formula into the cell as a String and have the user complete the process:

Sub pinocchio()
    Range("D3") = "'=1+2"
    MsgBox "User:  Make this into a real array formula"
End Sub

1 Comment

I SEE! That's creative. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.