I want to have rows in a worksheet not print if the value in a specific cell in the row is zero or blank. Manually hiding and unhiding the row is a pain, and formatting the row as hidden does not work as it displays and prints a blank row. I want to be able to see the row on the screen, but not have it print and not print a blank row. Just like hidden text in Word. Is there any way to do this?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Conditional hiding of cells when printing (2003)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Conditional hiding of cells when printing (2003)
- This topic has 14 replies, 2 voices, and was last updated 20 years, 9 months ago.
AuthorTopicWSasimpkins
AskWoody LoungerJuly 15, 2004 at 6:12 pm #407395Viewing 1 reply threadAuthorReplies-
WSHansV
AskWoody LoungerJuly 15, 2004 at 6:25 pm #851808You could create a macro that:
1) hides rows if a specific cell in that row is zero or blank
2) prints the worksheet
3) unhides the rows.
Assign this macro to a keyboard shortcut and/or custom toolbar button. Use this to print the sheet.
If you need help writing the macro, please provide more details. -
WSasimpkins
AskWoody LoungerJuly 15, 2004 at 6:44 pm #851818I had wondered about something along those lines, but I’m not a macro writer. What I want is to test all the cells in a column in a range (I want to exclude headers and totals from the test) and if a particular cell is blank or zero, then the row that contains that cell will not print. There could be no, one or several rows that meet the test.
-
WSHansV
AskWoody LoungerJuly 15, 2004 at 7:04 pm #851828That is not very specific, so you won’t get a specific answer. The following code assumes that the cell to be tested is in column A, and that you want to test rows 4 through 18.
Sub cmdPrint_Click()
Dim i As Long
‘ Loop through cells, hide row if necessary
For i = 4 To 18
If Range(“A” & i) = 0 or Range(“A” & i) = “” Then
Range(“A” & i).EntireRow.Hidden = True
End If
Next i
‘ Print
ActiveSheet.PrintOut
‘ Loop through cells to unhide rows
For i = 4 To 18
Range(“A” & i).EntireRow.Hidden = False
Next i
End Sub -
WSasimpkins
AskWoody LoungerJuly 15, 2004 at 7:56 pm #851854 -
WSHansV
AskWoody LoungerJuly 15, 2004 at 8:23 pm #851865Try this variation:
Sub cmdPrint_Click()
Dim oCell As Range
‘ Loop through cells, hide row if necessary
For Each oCell In ActiveSheet.Range(“Quantity”)
If oCell = 0 or oCell = “” Then
oCell.EntireRow.Hidden = True
End If
Next oCell
‘ Print
ActiveSheet.PrintOut
‘ Loop through cells to unhide rows
For Each oCell In ActiveSheet.Range(“Quantity”)
oCell.EntireRow.Hidden = False
Next oCell
Set oCell = Nothing
End Sub -
WSasimpkins
AskWoody LoungerJuly 16, 2004 at 3:57 pm #852227 -
WSHansV
AskWoody LoungerJuly 16, 2004 at 6:52 pm #852302You can create the command button in code when the workbook is opened, and delete is when the workbook is closed. But if you want to do it really professionally, it’s a lot of work – you would also have to hide the button when the user switches to another workbook and make it visible again when the user switches back. You can also put the toolbar button on a custom toolbar, attach the toolbar to the workbook and delete it each time you close the workbook. See for example post 321692.
-
WSHansV
AskWoody LoungerJuly 16, 2004 at 6:52 pm #852303You can create the command button in code when the workbook is opened, and delete is when the workbook is closed. But if you want to do it really professionally, it’s a lot of work – you would also have to hide the button when the user switches to another workbook and make it visible again when the user switches back. You can also put the toolbar button on a custom toolbar, attach the toolbar to the workbook and delete it each time you close the workbook. See for example post 321692.
-
WSasimpkins
AskWoody LoungerJuly 16, 2004 at 3:57 pm #852228 -
WSHansV
AskWoody LoungerJuly 15, 2004 at 8:23 pm #851866Try this variation:
Sub cmdPrint_Click()
Dim oCell As Range
‘ Loop through cells, hide row if necessary
For Each oCell In ActiveSheet.Range(“Quantity”)
If oCell = 0 or oCell = “” Then
oCell.EntireRow.Hidden = True
End If
Next oCell
‘ Print
ActiveSheet.PrintOut
‘ Loop through cells to unhide rows
For Each oCell In ActiveSheet.Range(“Quantity”)
oCell.EntireRow.Hidden = False
Next oCell
Set oCell = Nothing
End Sub
-
-
WSasimpkins
AskWoody LoungerJuly 15, 2004 at 7:56 pm #851855
-
-
WSHansV
AskWoody LoungerJuly 15, 2004 at 7:04 pm #851829That is not very specific, so you won’t get a specific answer. The following code assumes that the cell to be tested is in column A, and that you want to test rows 4 through 18.
Sub cmdPrint_Click()
Dim i As Long
‘ Loop through cells, hide row if necessary
For i = 4 To 18
If Range(“A” & i) = 0 or Range(“A” & i) = “” Then
Range(“A” & i).EntireRow.Hidden = True
End If
Next i
‘ Print
ActiveSheet.PrintOut
‘ Loop through cells to unhide rows
For i = 4 To 18
Range(“A” & i).EntireRow.Hidden = False
Next i
End Sub
-
-
WSasimpkins
AskWoody LoungerJuly 15, 2004 at 6:44 pm #851819I had wondered about something along those lines, but I’m not a macro writer. What I want is to test all the cells in a column in a range (I want to exclude headers and totals from the test) and if a particular cell is blank or zero, then the row that contains that cell will not print. There could be no, one or several rows that meet the test.
-
-
WSHansV
AskWoody LoungerJuly 15, 2004 at 6:25 pm #851809You could create a macro that:
1) hides rows if a specific cell in that row is zero or blank
2) prints the worksheet
3) unhides the rows.
Assign this macro to a keyboard shortcut and/or custom toolbar button. Use this to print the sheet.
If you need help writing the macro, please provide more details.
Viewing 1 reply thread -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Button Missing for Automatic Apps Updates
by
pmcjr6142
26 minutes ago -
Ancient SSD thinks it’s new
by
WSila
31 minutes ago -
Washington State lab testing provider exposed health data of 1.6 million people
by
Nibbled To Death By Ducks
4 hours, 31 minutes ago -
WinRE KB5057589 fake out
by
Susan Bradley
1 hour, 7 minutes ago -
The April 2025 Windows RE update might show as unsuccessful in Windows Update
by
Susan Bradley
10 hours, 42 minutes ago -
Firefox 137
by
Charlie
13 hours, 26 minutes ago -
Whisky, a popular Wine frontend for Mac gamers, is no more
by
Alex5723
16 hours, 54 minutes ago -
Windows 11 Insider Preview build 26120.3863 (24H2) released to BETA
by
joep517
17 hours, 6 minutes ago -
Windows 11 Insider Preview build 26200.5551 released to DEV
by
joep517
17 hours, 9 minutes ago -
New Windows 11 PC setup — can I start over in the middle to set up a local id?
by
ctRanger
10 hours, 14 minutes ago -
Windows 11 Insider Preview Build 26100.3902 (24H2) released to Release Preview
by
joep517
20 hours, 40 minutes ago -
Oracle kinda-sorta tells customers it was pwned
by
Nibbled To Death By Ducks
1 day, 2 hours ago -
Global data centers (AI) are driving a big increase in electricity demand
by
Kathy Stevens
1 day, 13 hours ago -
Office apps read-only for family members
by
b
1 day, 15 hours ago -
Defunct domain for Microsoft account
by
CWBillow
1 day, 12 hours ago -
24H2??
by
CWBillow
1 day, 2 hours ago -
W11 23H2 April Updates threw ‘class not registered’
by
WindowsPersister
20 hours, 56 minutes ago -
Master patch listing for April 8th, 2025
by
Susan Bradley
1 hour, 23 minutes ago -
TotalAV safety warning popup
by
Theodore Nicholson
11 hours, 56 minutes ago -
two pages side by side land scape
by
marc
3 days, 13 hours ago -
Deleting obsolete OneNote notebooks
by
afillat
3 days, 15 hours ago -
Word/Outlook 2024 vs Dragon Professional 16
by
Kathy Stevens
2 days, 18 hours ago -
Security Essentials or Defender?
by
MalcolmP
2 days, 21 hours ago -
April 2025 updates out
by
Susan Bradley
13 minutes ago -
Framework to stop selling some PCs in the US due to new tariffs
by
Alex5723
2 days, 14 hours ago -
WARNING about Nvidia driver version 572.83 and 4000/5000 series cards
by
Bob99
2 days, 4 hours ago -
Creating an Index in Word 365
by
CWBillow
3 days, 7 hours ago -
Coming at Word 365 and Table of Contents
by
CWBillow
1 day, 19 hours ago -
Windows 11 Insider Preview Build 22635.5170 (23H2) released to BETA
by
joep517
4 days, 10 hours ago -
Has the Microsoft Account Sharing Problem Been Fixed?
by
jknauth
4 days, 13 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.