You are here:

- Home
- Computing/Technology
- Business Software
- Excel
- array formulas in VBA

Advertisement

Hi Tom

I have the following array formula in a worksheet:

=IF($BA$10="","",IFERROR(INDEX(name,SMALL(IF(LEFT(Group2,LEN(SPtemplate2!$BA$10))=SPtemplate2!$BA$10,ROW(Group2)),ROW(A1)),1),""))

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

Next

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.

--

Regards,

Tom Ogilvy

- Add to this Answer
- Ask a Question

Rating(1-10) | Knowledgeability = 10 | Clarity of Response = 10 | Politeness = 10 |

Comment | Thanks Tom this works as I anticipated. |

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

Excel

Answers by Expert:

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. **Education/Credentials**

Master of Science (MS) degree Operations Research (ORSA)**Awards and Honors**

Microsoft MVP in Excel.