hide rows in specific range before printing

already

Board Regular
Joined
Nov 11, 2008
Messages
179
Hello

I want to hide rows with empty data in a column (D) but only in a specific part(range A11:D39) of the worksheet before printing. I though that following part of code could do the job but I'm wrong

With ActiveSheet

On Error Resume Next
Set rng = Sheets("Sheet1").Range("A11:D39")
.Columns("d").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
.PrintOut
.Columns("d").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = False
On Error GoTo 0
End With

Any help will be appreciated

kind regards

Al
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Code:
Dim cl As Range
Dim rng As Range
With ActiveSheet

On Error Resume Next
Set rng = Sheets("Sheet1").Range("D11:D39")
For Each cl In rng
If cl.Value = "" Then cl.EntireRow.Hidden = True
Next
.PrintOut
For Each cl In rng
cl.EntireRow.Hidden = False
Next

On Error GoTo 0
End With
 
Upvote 0
Code:
Sub Hide_Blank_DRows()

    Dim rng As Range, c as Range
    
    Set rng = Sheets("Sheet1").Range("A11:D39")
    For each c in rng
         If IsBlank(c) Then c.EntireRow.Hidden = True
    Next c
    ActiveSheet.PrintOut
    rng.EntireRow.Hidden = False

End Sub
 
Last edited:
Upvote 0
...........I think AlphaFrog's will pick up the blank cells in the other columns - possibly hiding rows you wish to keep visible (as per your original code) but I believe you only actually wish to hide rows with blanks in column D.
However, the specialcells method's cleaner, so this is a sawn-off version of my previous:
Code:
Dim rng As Range

    With ActiveSheet
        On Error Resume Next
            Set rng = Sheets("Sheet1").Range("D11:D39")
            rng.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
            .PrintOut
            rng.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = False
        On Error GoTo 0
    End With
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,820
Members
449,469
Latest member
Kingwi11y

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