VBA code to store an array formula

learningexcel123

New Member
Joined
May 1, 2010
Messages
13
Can someone help me determine the right code to store an array formula into a cell? For example, I can use the below to store a non-array formula but how do I modify it to store an array formula? (i.e. with the curly braces on the outside) Generally, we would have to hold down Control+Shift+Enter to change a formula to an array formula but not sure how to do in VBA.

Sub Update_Header_Formulas()
Dim ws As Worksheet
For Each ws In Sheets(Array("Sheet1"))
ws.Range("E4").Formula = "=IF(ISNA(VLOOKUP($C$3&""*"",'[Mar_costs.xlsx]data'!$A$11:$Z$1239,7,0))=TRUE,"""",VLOOKUP($C$3&""*"",'[Mar_costs.xlsx]data'!$A$11:$Z$1239,7,0))"
Next ws
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

hiker95

Well-known Member
Joined
Apr 8, 2009
Messages
17,649
learningexcel123,

Try:


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


Code:
ws.Range("E4").FormulaArray = "=IF(ISNA(VLOOKUP($C$3&""*"",'[Mar_costs.xlsx]data'!$A$11:$Z$1239,7,0))=TRUE,"""",VLOOKUP($C$3&""*"",'[Mar_costs.xlsx]data'!$A$11:$Z$1239,7,0))"
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi learningexcel123

You do realise what you posted wasn't an array formula though? I asume it was just an example. Be aware that you have a maximum formula length of 255 characters when using the FormulaArray property to assign an array formula.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,259
Messages
5,769,082
Members
425,516
Latest member
Melzebu

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
Top