Hi
I have a code that works perfectly however it is long and takes a while to run - can anyone help to shorten the code? The code basically looks at different sections and hides rows if all columns contain 0.
I have a code that works perfectly however it is long and takes a while to run - can anyone help to shorten the code? The code basically looks at different sections and hides rows if all columns contain 0.
Code:
Sub HideRows()
Dim i As Long
Dim j As Long
Dim hide As Boolean
For i = 6 To 15
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 19 To 20
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 24 To 32
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 36 To 67
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 73 To 75
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 79 To 80
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 84 To 87
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 91 To 96
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 102 To 112
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 116 To 117
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 121 To 124
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 128 To 131
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 135 To 140
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 144 To 161
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 165 To 169
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 173 To 179
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
For i = 183 To 190
hide = True
For j = 3 To 56
If Cells(i, j).Value > 0 Then
hide = False
Exit For
End If
Next j
Rows(i).Hidden = hide
Next i
End Sub
Last edited by a moderator: