How to print only nonblank rows?

W

will0707

I need to do a template for a bill of material. Therefore when the use
will fill up the bill, some rows will stay empty. I would like to kno
how if someone know a macro which allow to print only the nonblan
rows. Some cells of the empty rows will have text, so the conditio
will be if cell of column "A" is empty then hide the entire row.I
possible I would like that the macro is ran when the user press th
print button.
Thank yo
 
R

Ron de Bruin

Hi will0707

Try this

Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
ActiveSheet.PrintOut
Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = False
 
D

David

Ron de Bruin wrote
Try this

Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
ActiveSheet.PrintOut
Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = False

Actually, that won't work if the Print button is pressed as the OP wants.
The rows are never unhidden.

A few months back, someone here pointed me to a site that explained things
and led to this solution:

ThisWorkbook module
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
Application.OnTime Now(), ThisWorkbook.Name & "!WorkbookAfterPrint"
End Sub

General module
Sub WorkbookAfterPrint()
Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = False
End Sub
 
D

David

Never mind.
Added "On Error GoTo Quit" following Quit: with
Application.EnableEvents = True
Application.ScreenUpdating = True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top