Unable to set the FormulaArray property of the Range Class

nniedzielski

Well-known Member
Joined
Jan 8, 2016
Messages
598
Office Version
  1. 2019
Platform
  1. Windows
Looking to put this formula into a cell, but get the Run-time Error '1004': Unable to set the FormulaArray property of the Range Class, is there a solution to get Excel to accept this formula?

VBA Code:
Dim lr As Long, sh As Worksheet, cad1 As String, cad2 As String, cad3 As String, i As Long
    Set sh = Sheets("Yard")
    lr = sh.Range("A" & Rows.Count).End(xlUp).Row
    cad1 = "'" & sh.Name & "'!" & sh.Range("$C$2:$C$" & lr).Address
    cad2 = "'" & sh.Name & "'!" & sh.Range("$A$2:$A$" & lr).Address
    cad3 = "'" & sh.Name & "'!" & sh.Range("$A$2:$C$" & lr).Address
    For i = 2 To Range("B" & Rows.Count).End(xlUp).Row
      Range("D" & i).FormulaArray = _
        Replace(Replace(Replace("=IFERROR(INDEX(#,SUMPRODUCT((IF(--ISNUMBER(FIND(@,B" & i & "))," & _
        "LEN(@))=(MAX(IF(--ISNUMBER(FIND(@,B" & i & ")),LEN(@)))))*(ROW(@)))-1)," & _
        "VLOOKUP(""*""&B" & i & "&""*"",|,3,0))", "#", cad1), "@", cad2), "|", cad3)
    Next

thank you!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You're probably over the 255 character limit for .FormulaArray. (But you'll also get the same message if the worksheet is protected).

You are sort of on the right track, using .Replace, but you need to do it in two steps:
- Put an abridged formula into Excel (<=255 characters)
- Make the text replacement(s) to the formula in Excel.

Have a look here, for example: Entering Long Array Formulas in VBA – Daily Dose of Excel
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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