ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Hiding Rows when printing (https://www.excelbanter.com/excel-worksheet-functions/132006-hiding-rows-when-printing.html)

pano

Hiding Rows when printing
 
Hi, now J Latham provided this to me, I am no WHIZZ with formulas and
have finally found out where to put it. I wonder if some kind person
could help me out. Now this works without any run time errors but
does'nt do what it is supposed to do the whole sheet comes up empty
rows as well

The column and rows I wish to check and hide before printing are cells
J10 to J44 now each cell has a formula in it which picks up a postcode
from another sheet. If a cell from J10 to J44 does not have that
postcode in it I want the entire row hidden so it wont print.

A big thanks to the helpee
Stephen

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim mySpecialRange As Range
Dim anyCell As Range


Set mySpecialRange = Worksheets("Carlog"). _
Range("A1:A" & Worksheets("Carlog").UsedRange.Rows.Count)
'unhide any that may now have data in them
mySpecialRange.EntireRow.Hidden = False
'hide rows based on blanks in column A
'but cells have formulas in them so...
For Each anyCell In mySpecialRange
If anyCell = "" Then
anyCell.EntireRow.Hidden = True
End If
Next
End Sub


Now, all that needs to be done from your button is to tell Excel to
print
that sheet:


Sub PrepAndPrintCarlogSheet()
Sheets("Carlog").PrintOut
End Sub


Assign that macro to the button and you're done.


Dave Peterson

Hiding Rows when printing
 
Check your previous thread.

pano wrote:

Hi, now J Latham provided this to me, I am no WHIZZ with formulas and
have finally found out where to put it. I wonder if some kind person
could help me out. Now this works without any run time errors but
does'nt do what it is supposed to do the whole sheet comes up empty
rows as well

The column and rows I wish to check and hide before printing are cells
J10 to J44 now each cell has a formula in it which picks up a postcode
from another sheet. If a cell from J10 to J44 does not have that
postcode in it I want the entire row hidden so it wont print.

A big thanks to the helpee
Stephen

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim mySpecialRange As Range
Dim anyCell As Range

Set mySpecialRange = Worksheets("Carlog"). _
Range("A1:A" & Worksheets("Carlog").UsedRange.Rows.Count)
'unhide any that may now have data in them
mySpecialRange.EntireRow.Hidden = False
'hide rows based on blanks in column A
'but cells have formulas in them so...
For Each anyCell In mySpecialRange
If anyCell = "" Then
anyCell.EntireRow.Hidden = True
End If
Next
End Sub

Now, all that needs to be done from your button is to tell Excel to
print
that sheet:

Sub PrepAndPrintCarlogSheet()
Sheets("Carlog").PrintOut
End Sub

Assign that macro to the button and you're done.


--

Dave Peterson


All times are GMT +1. The time now is 02:35 AM.

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