RawlinsCross
Active Member
- Joined
- Sep 9, 2016
- Messages
- 437
Good day,
I have a sub routine that scans down through a 2-dimensional range and checks for hidden rows. If the row is not hidden, it puts that row in an array. Nothing wrong with the code, works great - although it slows down at very large rows.count. I've done speed tests where I remove the 'For Loop' and it's clearly that section of code that is causing the issue. Is there a way to replace that 'For Loop' and still get the same effect (i.e. non-hidden rows in an array)?
I have a sub routine that scans down through a 2-dimensional range and checks for hidden rows. If the row is not hidden, it puts that row in an array. Nothing wrong with the code, works great - although it slows down at very large rows.count. I've done speed tests where I remove the 'For Loop' and it's clearly that section of code that is causing the issue. Is there a way to replace that 'For Loop' and still get the same effect (i.e. non-hidden rows in an array)?
VBA Code:
Dim wSht As Worksheet
Dim rRange As Range
Dim vArray As Variant
Dim i As Long, j As Long, iCount As Long
Set wSht = ThisWorkbook.Worksheets("WOs")
Set rRange = wSht.Range("rngWOs")
ReDim vArray(1 To rRange.Rows.Count, 1 To 20)
For i = 1 To rRange.Rows.Count
If rRange.Rows(i).Hidden = False Then
iCount = iCount + 1
For j = 1 To rRange.Columns.Count
vArray(iCount, j) = rRange.Cells(i, j)
Next j
End If
Next i
'Redimension
vArray = Application.Transpose(vArray)
ReDim Preserve vArray(1 To 20, 1 To iCount)
vArray = Application.Transpose(vArray)
'Call another procedure that does something with the vArray
End Sub