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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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))"
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,215,424
Messages
6,124,817
Members
449,190
Latest member
rscraig11

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