Is there a way to make this code run faster? I am trying to hide rows that are blank across multiple worksheets.
Option Explicit
Private Sub HideRows_Click()
Dim ws As Worksheet, c As Range
Application.ScreenUpdating = False
On Error Resume Next
For Each ws In ThisWorkbook.Worksheets
Select Case ws.Name
Case "Sheet1", "Sheet2", "Sheet3"
'sheets to exclude
'do nothing
Case Else 'hide rows on these sheets
For Each c In ws.Range("AJ16:AJ153,AJ157:AJ292")
c.EntireRow.Hidden = c.Value = 0
Next c
End Select
Next ws
Application.ScreenUpdating = True
End Sub
Here are some of the changes made to your code with the intention of speeding it up:
AJ
with no values via theUnion()
function and then callingEntireRow.Hide
on that combined rangeIt was honestly pretty clean code to begin with!