You are here:

Excel/array formulas in VBA


Hi Tom

I have the following array formula in a worksheet:

It is copied through rows BA12:BA60.   The worksheet is duplicated several times across the whole workbook.  I am concerned that this is increasing the time that it takes to save the workbook.

The formula is located in worksheet: “SPtemplate2”.  Can an array formula be written in VBA?  If so could you possibly do this for me and tell me where to place it?

Thanks in advance

Chris Mitchell

Christopher Mitchell,

If wanted to run a macro that puts in that formula and then replaces it with the results you would need to know where to put it.  Lets say you want to put the formula in Range A1:A100 of the activeworksheet

Sub ABC()
Dim cell as Range
Dim i as long
i = 0
for each cell in Range("A1:A100")
 i = i + 1
 cell.formulaArray = "=IF($BA$10="""","""",IFERROR(INDEX(name," & _
  "SMALL(IF(LEFT(Group2,LEN(SPtemplate2!$BA$10))=SPtemplate2!$BA$10," & _
  "ROW(Group2)),ROW(A" & i & ")),1),""""))"
 cell.formula = cell.value
End Sub

So you would run this macro whenever you wanted cells A1:A100 updated.  

Always test new code on a copy of your owrkbook until you are satisfied it behaves as expected.

Tom Ogilvy  
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Tom Ogilvy


Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]


Extensive experience.

Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 All rights reserved.