Getting a list of excel formula arrays in VBA

enzovitale

New Member
Joined
Jun 27, 2011
Messages
3
Dear all,
I need to get a list of all formula arrays in the current sheet. I'd like to do this in VBA.

It would be very nice if Microsoft provided an 'Arrays' property of the Workbook and Worksheet objects, like they do for e.g. the 'Names' collection. Then, I could just query this property.

Since to my knowledge they don't, I wrote the code below, which works nicely but is quite SLOW. Any suggestions?

Enzo



Dim UsedRange As Excel.Range
Set UsedRange = ActiveSheet.UsedRange

Dim DictionaryArrays As Scripting.Dictionary
Set DictionaryArrays = New Scripting.Dictionary

' Build up a collection of all distinct array ranges
' by looping over all cells in the used range.
If Not UsedRange.HasArray = False Then
For Each iCell In UsedRange
If iCell.HasArray Then
Set iArray = iCell.CurrentArray
If Not DictionaryArrays.Exists(iArray.Address) Then
Call DictionaryArrays.Add(iArray.Address, iArray)
End If
End If
Next
End If
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try to set Application.ScreenUpdating = False in the beginning of procedure.
 
Upvote 0
You can restrict your search to just formula cells in the sheet too by using the SpecialCells method:

Code:
For Each iCell In UsedRange.SpecialCells(xlCellTypeFormulas)
 
Upvote 0
thanks a lot Richard!

Indeed there's no array in Excel without a formula attached to it, right? I mean, even array constants (which I'd like to capture in my routine) are defined through formulas. Hence, your approach should just work!

Enzo
 
Upvote 0
You can test for an array once you're in the cell:

Code:
Sub ShowArrays()
    Dim c As Range
    
    For Each c In Cells.SpecialCells(xlCellTypeFormulas)
        If c.HasArray Then
            Debug.Print c.Address & "; " & c.FormulaArray
        End If
    Next c
End Sub

Denis
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,841
Members
452,948
Latest member
UsmanAli786

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