Hiding Empty Rows
On Apr 10, 5:34 am, Dave Peterson wrote:
How about:
Option Explicit
Sub Test_Hide_Rows2()
Dim iRow As Long
Dim myRngToCheck As Range
Dim HowManyCols As Long
HowManyCols = 12 'D to O is 12 columns
With ActiveSheet
For iRow = 8 To 359 'All Rows
Set myRngToCheck = .Cells(iRow, 4).Resize(1, HowManyCols)
If Application.CountIf(myRngToCheck, 0) = HowManyCols Then
'all 0!
.Rows(iRow).Hidden = True
End If
Next iRow
End With
End Sub
AJ Master wrote:
On Apr 9, 4:42 pm, OssieMac
wrote:
Try this. It ran in less than a second for me. Let me know how it goes.
Sub Test_Hide_Rows()
Dim lngRow As Integer
Application.ScreenUpdating = False
With ActiveSheet
For lngRow = 8 To 359 'AllRows
If .Cells(lngRow, 4) = 0 Then
If .Cells(lngRow, 4).End(xlToRight).Column 15 Then
.Cells(lngRow, 4).EntireRow.Hidden = True
End If
End If
Next lngRow
End With
Application.ScreenUpdating = True
End Sub
Regards,
OssieMac
"AJ Master" wrote:
I have been using the code below to hideemptyrowsin a worksheet.
Originally I was only evaluating 12 columns (one for each month of
the year) in each of about 100rowsto determine whether to hide the
entire row. The number ofrowshas grown to about 350 and now the
code runs rather slow. About 7-10secs versus the 2 secs it used to
take. Anyone with any ideas on how to improved the speed of this
code??
Dim bytCol As Byte
Dim lngRow As Integer
Application.ScreenUpdating = False
For lngRow = 8 To 359 'AllRows
For bytCol = 4 To 15 'Columns D-O
If ActiveSheet.Cells(lngRow, bytCol) < 0 Then Exit For
If bytCol = 15 Then ActiveSheet.Rows(lngRow).Hidden = True
Next bytCol
Next lngRow
Application.ScreenUpdating = True
Thanks....AJ
OssieMac,
Thanks for your quick reply. I tried your code, but its hiding rows
that it shouldn't. I have to check every column D thru O (ie. 4 to
15) to see if the value is something other than zero. If the value in
each column (D thru O) has a zero value then I can hide the row. Any
tweak that might fix your code?
--
Dave Peterson
Dave,
Thanks very much! The new code works great and I'm back to the 2-3
sec execution range.
Regards...AJ
|