PDA

View Full Version : [SOLVED:] Can I create an Array from 1 to AutoFilter.Range.Columns.Count



frank_m
11-29-2011, 01:56 AM
I have 30 columns, all with Headers, but it often varies as to how many are using the autofilter.

How might I create an Array from 1 to the last column in the Autofilter range


Dim ArrCols As Variant
Dim LastFiltCol As Integer
LastFiltCol = AutoFilter.Range.Columns.Count
'For example, if there are 7 columns in the Autofilter range, I want the equivilant to:
'ArrCols = Array(1, 2, 3, 4, 5, 6, 7)
'Wrong of course but hopefully something similar to:
ArrCols = Array(1, LastFiltCol)

Thanks

Aflatoon
11-29-2011, 02:36 AM
You could loop or use something like this:

ArrCols = Application.Transpose(Evaluate("ROW(1:" & LastFiltCol & ")"))

frank_m
11-29-2011, 02:46 AM
That does the trick

Thanks Aflatoon