VBA to hide rows based on formula blank...

Matty

Well-known Member
Joined
Feb 17, 2007
Messages
3,717
Hi,

I'm looking for a piece of code for hiding a non-contiguous set of rows in a Worksheet based on the value in column B being a formula blank (i.e. ="")

At the moment I have this, but it makes my Workbook grind to a halt:

Code:
Sub HideBlankRows()
    Application.ScreenUpdating = False
    
    With Sheet8
        .Calculate
        For Each c In .Range("B7:B156, B165:B239, B244:B318, B323:B337, B342:B356")
            c.EntireRow.Hidden = c.Value = ""
        Next c
    End With
    
    Application.ScreenUpdating = True
    
End Sub

I've seen autofilter used before, but the problem is that my range isn't contiguous.

Anyone got any bright ideas?

Thanks,

Matty
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try this slight modification

Code:
Option Explicit


Sub HideBlankRows()
Dim c As Range
    Application.ScreenUpdating = False
    
    With Sheet8
            For Each c In .Range("B7:B156, B165:B239, B244:B318, B323:B337, B342:B356")
            If c.Value = "" Then
            c.EntireRow.Hidden = True
            End If
        Next c
    End With
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Thanks Alan, but it's made little difference.

I think the problem is due to the fact that there are some fairly heavy formulas on the Worksheet and Excel is, seemingly, recalculating each time a row is hidden (even though calculation is set to Manual).

Cheers,

Matty
 
Upvote 0
Just a thought.. How about color those entire row yellow and filter by color and hide them..
 
Upvote 0
Hi,

I've gone with the following, which seems to perform very well:

Code:
Sub HideBlankRows()

    Application.ScreenUpdating = False
    
    With Sheet8
        .Calculate
        With .Range("B7:B156, B165:B239, B244:B318, B323:B337, B342:B356")
            .EntireRow.Hidden = False
            .SpecialCells(xlCellTypeFormulas, 2).EntireRow.Hidden = True
        End With
    End With
    
    Application.ScreenUpdating = True
    
End Sub

Need to test it on a larger data set tomorrow at work, but I'm confident.

Cheers for everyone's input.

Matty
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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