Hery0502
Hery0502

Reputation: 91

Add Union to increase efficiency in VBA code

I have code within a workbook that works exactly how I want it to, but I am looking for ways to increase its efficiency/speed. My thought would be to add a union for all blank rows and hide that range all at once. Can this be done?

    Sub HideRws()
   Dim Rng As Range, Cl As Range
   With Sheet3
      For Each Cl In .Range("A11:A60")
         Cl.EntireRow.Hidden = Cl.Value = ""
      Next Cl
      For Each Rng In .Range("A71:A120, A131:A180, A190:A239").Areas
         If Rng(1) = "" Then
            Rng.Offset(-6).Resize(58).EntireRow.Hidden = True
         Else
            For Each Cl In Rng
               Cl.EntireRow.Hidden = Cl.Value = ""
            Next Cl
         End If
      Next Rng
   End With
End Sub

Upvotes: 0

Views: 228

Answers (1)

StoneGiant
StoneGiant

Reputation: 1497

I think this does the same thing:

Sub HideRows()
    With Sheet3
        .Range("A11:A60").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
        For Each Rng In .Range("A71:A120, A131:A180, A190:A239").Areas
            If Rng(1) = "" Then
                Rng.Offset(-6).Resize(58).EntireRow.Hidden = True
            Else
                Rng.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
            End If
        Next Rng
    End With
End Sub

Upvotes: 1

Related Questions