ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Hiding rows when printing (https://www.excelbanter.com/excel-discussion-misc-queries/89736-hiding-rows-when-printing.html)

DHallam

Hiding rows when printing
 

Hi all,

I have this code that works really well for hiding rows when they do
not have anything in. However the rows I need to hide all have
formulas in as they pull data from other worksheets and therefore this
code doesnt work. Does anyone know how i can get over this?

The code i currently have is this:

Sub Hide_Print_Unhide()
Dim rw As Long
Application.ScreenUpdating = False

With Sheets("Sheet1")
For rw = 1 To 30
If Application.WorksheetFunction.CountA( _
.Cells(rw, 1).Range("A1:G1")) = 0 Then _
.Rows(rw).Hidden = True
Next rw
.PrintPreview
.Range("A1:A30").EntireRow.Hidden = False
End With

Application.ScreenUpdating = True
End Sub


--
DHallam
------------------------------------------------------------------------
DHallam's Profile: http://www.excelforum.com/member.php...o&userid=25253
View this thread: http://www.excelforum.com/showthread...hreadid=544050


Roger Govier

Hiding rows when printing
 
Hi

You could try changing the test for the blank lines to

If Application.WorksheetFunction.CountBlank( _
Cells(rw, 1).Range("A1:G1")) = 7 Then _
Rows(rw).Hidden = True


--
Regards

Roger Govier


"DHallam" wrote
in message ...

Hi all,

I have this code that works really well for hiding rows when they do
not have anything in. However the rows I need to hide all have
formulas in as they pull data from other worksheets and therefore this
code doesnt work. Does anyone know how i can get over this?

The code i currently have is this:

Sub Hide_Print_Unhide()
Dim rw As Long
Application.ScreenUpdating = False

With Sheets("Sheet1")
For rw = 1 To 30
If Application.WorksheetFunction.CountA( _
Cells(rw, 1).Range("A1:G1")) = 0 Then _
Rows(rw).Hidden = True
Next rw
PrintPreview
Range("A1:A30").EntireRow.Hidden = False
End With

Application.ScreenUpdating = True
End Sub


--
DHallam
------------------------------------------------------------------------
DHallam's Profile:
http://www.excelforum.com/member.php...o&userid=25253
View this thread:
http://www.excelforum.com/showthread...hreadid=544050





All times are GMT +1. The time now is 05:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com