VBA code to hide blank rows

scoha

Active Member
Joined
Jun 15, 2005
Messages
428
Is there a more efficient way to code this series of snippets which hide all blank lines between specific non contiguous ranges over a few sheets?

Code:
'Hides blank rows

    Set Rng = Range("$C$9:$C$95,$C$101:$C$198")
    
    For Each Area In Rng.Areas
        For Each Cell In Area
            If Cell.Value = "" Then Cell.EntireRow.Hidden = True
        Next Cell
    Next Area
    
    
    
    Set Rng = Sheets("WI").Range("WI451Names")
    
    For Each Area In Rng.Areas
       For Each Cell In Area
            If Cell.Value = "" Then Cell.EntireRow.Hidden = True
        Next Cell
    Next Area
    
    Set Rng = Sheets("Bits").Range("Bits451Names")
    
    For Each Area In Rng.Areas
       For Each Cell In Area
            If Cell.Value = "" Then Cell.EntireRow.Hidden = True
        Next Cell
    Next Area
    
    
    Set Rng = Sheets("PPE").Range("PPE451Names")
    
    For Each Area In Rng.Areas
       For Each Cell In Area
            If Cell.Value = "" Then Cell.EntireRow.Hidden = True
        Next Cell
    Next Area
    
    Set Rng = Sheets("WI").Range("WI454Names")
    
    For Each Area In Rng.Areas
       For Each Cell In Area
            If Cell.Value = "" Then Cell.EntireRow.Hidden = True
        Next Cell
    Next Area
    
    Set Rng = Sheets("Bits").Range("Bits454Names")
    
    For Each Area In Rng.Areas
       For Each Cell In Area
            If Cell.Value = "" Then Cell.EntireRow.Hidden = True
        Next Cell
    Next Area
    
    
    Set Rng = Sheets("PPE").Range("PPE454Names")
    
    For Each Area In Rng.Areas
       For Each Cell In Area
            If Cell.Value = "" Then Cell.EntireRow.Hidden = True
        Next Cell
    Next Area
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Sure.

Code:
Sub Wigi()

    HideRows Range("C9:C95,C101:C198")
    HideRows Sheets("WI").Range("WI451Names")
    HideRows Sheets("Bits").Range("Bits451Names")
    HideRows Sheets("PPE").Range("PPE451Names")
    HideRows Sheets("WI").Range("WI454Names")
    HideRows Sheets("Bits").Range("Bits454Names")
    HideRows Sheets("PPE").Range("PPE454Names")

End Sub

Sub HideRows(rng As Range)

    On Error Resume Next
    rng.SpecialCells(4).EntireRow.Hidden = True
    On Error GoTo 0

End Sub

First test with the 'On Error ...' lines commented out. When it runs fine, you can remove the comment indicators ' in front of the lines.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top