Array Formulas in VBA

UniMord

Active Member
Joined
May 6, 2002
Messages
311
I'd like to count the number of errors in Selection.

The most straightforward way, it seems to me, would be to use a single array formula: {=SUM(0+ISERROR(SELECTION))}

This can be entered into a cell with Selection.FormulaArray, but I don't want to enter it into a cell, I need the value inside a subroutine.

In short: can an Array formula be used in VBA without actually entering it into a cell, or do I have to go the loop route? (Or are there other options?)
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I think you can use Evaluate to get what you want. If I recall correctly, Evaluate treats the formula as an array...
 
Upvote 0
Something like this worked on my test sheet:

Code:
Dim i As Long

i = Application.Evaluate("SUM(0+ISERROR(A1:A10))")
 
Upvote 0
Thanks a million, guys! Too bad VBA Help couldn't be troubled to document this very cool feature of Evaluate. For that matter, none of my VBA books mention it either. If it's not a closely guarded secret, can you please tell me where you learned that?
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

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