Enter array formula to cell - over 255 characters - Error 1004 ArrayFormula VBA

Celticfc

Board Regular
Joined
Feb 28, 2016
Messages
153
Hi all,

I'm trying to put the below code to VBA and send it to cell A2 but it won't work. I had a look on Google that its over 255 characters so tried to split the code into two variables but would still not work.

Code:
=IFERROR(INDEX('https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!$A:$BX,SMALL(IF('https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!$B:$B=filter, ROW('https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!$B:$B)),ROW(1:1)),COLUMN()),"")

I've tried many things in the lines of below but would not work...

Any support is appreciated.

Code:
Sub Macro1()
'
' Macro1 Macro
'
Dim x1 As String
Dim x2 As String
   ' range("a2").select
     x1 = "=IFERROR(INDEX('https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!C1:C76,SMALL(IF('https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/"
     x2 = "[el.xlsx]formulationsTK'!C2=filter, ROW('https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!C2)),ROW(R)),COLUMN()),"""")"
 Selection.FormulaArray = _
 x1 & x2
 
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi

You can enter a formula with the same structure of yours (with a syntax accepted by excel) and then use replace to reconstruct it.

For ex., looking at your formula, it has the same structure as:

=IFERROR(INDEX(111111,SMALL(IF(222222=filter,333333,ROW(1:1)),COLUMN())),"")

which is a small array formula with a correct syntax that excel will accept, where

111111 stands in place of 'https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!C1:C76
222222 stands in place of 'https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!$B:$B
333333 stands in place of ROW('https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!$B:$B)

You can then implement it with vba:

Code:
Sub Test()

With Range("A2")
    .FormulaArray = "=IFERROR(INDEX(111111,SMALL(IF(222222=filter,333333,ROW(1:1)),COLUMN())),"""")"
    .Replace 111111, "'https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!C1:C76"
    .Replace 222222, "'https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!$B:$B"
    .Replace 333333, "ROW('https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!$B:$B)"
End With
End Sub

Please try.
 
Upvote 0
Hi

You can enter a formula with the same structure of yours (with a syntax accepted by excel) and then use replace to reconstruct it.

For ex., looking at your formula, it has the same structure as:

=IFERROR(INDEX(111111,SMALL(IF(222222=filter,333333,ROW(1:1)),COLUMN())),"")

which is a small array formula with a correct syntax that excel will accept, where

111111 stands in place of 'https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!C1:C76
222222 stands in place of 'https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!$B:$B
333333 stands in place of ROW('https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!$B:$B)

You can then implement it with vba:

Code:
Sub Test()

With Range("A2")
    .FormulaArray = "=IFERROR(INDEX(111111,SMALL(IF(222222=filter,333333,ROW(1:1)),COLUMN())),"""")"
    .Replace 111111, "'https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!C1:C76"
    .Replace 222222, "'https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!$B:$B"
    .Replace 333333, "ROW('https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!$B:$B)"
End With
End Sub

Please try.

Hello,

Yes I've actually managed to get around this, I wasn't aware that each condition had the be a proper formula for Excel to accept. I've used the code below, thank you again.

Code:
Sub Macro1()
'
' Macro1 Macro
'
'
   
   Dim e1 As String
   Dim e2 As String
   
     e1 = "=(INDEX('https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!$A:$BX,SMALL(IF('https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!$B:$B=filter,),)))"
     e2 = "ROW('https://wels.sharepoint.com/sites/GroupSites7/blue/Talent/Shared Documents/[el.xlsx]formulationsTK'!$B:$B)),ROW(1:1)),COLUMN()))"
Range("e18").Select
 With Selection
.FormulaArray = e1
.Replace "),)))", e2

End With
End Sub
 
Upvote 0
p.s. this also worked great -,

just thinking, can I use the above method to enter array into multiple ranges?

i.e. I need the same code in a2:150, e2:e150, f2:j150

Is there a way to incorporate the code above in to one line so that I do not have to enter it again and again?

Many thanks.
 
Upvote 0
Hi

I'm glad you figured it out.

If you want the formula in the rows below, after the code that writes the formula in A2, use

Code:
Range("A2:A10").FillDown
 
Upvote 0
Hi

I'm glad you figured it out.

If you want the formula in the rows below, after the code that writes the formula in A2, use

Code:
Range("A2:A10").FillDown

Hello again,

Sorry for coming back to you,

I’m trying to put the code to a2:a10, c2:c10 and au2:au50

Is there a quick way of doing this?

Thank you for your support.
 
Upvote 0

Forum statistics

Threads
1,224,826
Messages
6,181,192
Members
453,021
Latest member
pingpong7117

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