Excel/Vba code Help


I am looking for help on a code that would search column H for blank cells then hide that row.
It would then Print from "A1:G?" which would be the last remaining row. There are about 400 rows.
Then I would like it to unhide the hidden rows.
I will be using this code so it does the exact same thing with the exact same range on 9 sheets in the same workbook.Of course it would be nice if it could do all 9 sheets at the same time.

Any help would be greatly appreciated.

The following will happen automatically when you try to print.
In the VBE, double-click the "ThisWorkbook" in the Project window, and enter this code:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
   For Each sh In Sheets
       sh.Range("H:H").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
   Application.OnTime Now, "Unhide"
End Sub

In a regular module (Insert/Module), put this code:

Sub Unhide()
   For Each sh In Sheets
       sh.Rows.Hidden = False
End Sub
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Bob Umlas


I`m a Microsoft Excel MVP (Most Valuable Professional) and have been since the inception of the program in 1995. I can answer every kind of Excel question except: API, Importing/exporting to other programs (powerpoint, word,...) Also check out my in-person training link at http://www.thumbtack.com/ny/new-york/excel-training/


Worked with MS Excel since version 0.99 (on the Mac!). Was contributing editor to Excellence Magazine, having written >300 articles. John Walkenbach said of me "I finally met someone who knows as much about Excel as I do."

Excellence, The Expert, Microsoft

BA in math, Hofstra University, 1965

Awards and Honors
Led sessions for the Convergence 2004-2006 seminar on Excel tips & tricks

©2017 About.com. All rights reserved.