Hello all,
Someone please put me out of my misery! I have tried various approaches but have been unable to get a filtered range to a 2D array. The bellow code only seems to be picking up the header row.
What I'm trying to do:
I have a pre filtered sheet. I would like to suck up only the visible rows of data and paste them to a sheet 2.
problems:
while the select statement i have in here for debugging is selecting the correct cells , rng.Rows.count is returning a 1
Can someone please point out where this is going wrong?
thank you!
Someone please put me out of my misery! I have tried various approaches but have been unable to get a filtered range to a 2D array. The bellow code only seems to be picking up the header row.
What I'm trying to do:
I have a pre filtered sheet. I would like to suck up only the visible rows of data and paste them to a sheet 2.
problems:
while the select statement i have in here for debugging is selecting the correct cells , rng.Rows.count is returning a 1
Can someone please point out where this is going wrong?
thank you!
VBA Code:
Private Sub grabResults_Click()
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
With ws
' With ws.Range("A13:W13")
'
' .AutoFilter Field:=7, Criteria1:=">0"
'
' End With
Dim rng As Range
Dim rng1 As Range
Dim rngArea As Range
Dim ar As Variant
Dim sh As Worksheet
Dim i As Long
Dim j As Long
RowCount = ws.Range("A" & Rows.count).End(xlUp).Row
Set rng1 = ws.Range("A13:W" & RowCount)
Set rng = rng1.SpecialCells(xlCellTypeVisible)
'rng.Select 'for debugging, this is selecting the correct cells...
Set sh = ws
ReDim ar(1 To rng.Rows.count, 1 To 23) ' rng.Rows.count is returning a 1
For Each rngArea In rng.Areas
For Each rng1 In rngArea
i = i + 1
For j = 0 To 22
ar(i, 1 + j) = rng1.Offset(0, j)
Next j
Next rng1
Next rngArea
Sheet2.Range("A1").Resize(UBound(ar), 4) = ar
End sub