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?
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
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, 10 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
-
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
19 minutes ago -
184 MILLION Passwords on FBook, Google, MS & Netflix hacked/leaked
by
ClearThunder
2 hours, 46 minutes ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
3 hours ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
5 hours, 47 minutes ago -
Windows Update orchestration platform to update all software
by
Alex5723
10 hours, 20 minutes ago -
May preview updates
by
Susan Bradley
11 hours, 58 minutes ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
47 minutes ago -
Just got this pop-up page while browsing
by
Alex5723
2 hours, 31 minutes ago -
KB5058379 / KB 5061768 Failures
by
crown
3 hours, 58 minutes ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
1 minute ago -
At last – installation of 24H2
by
Botswana12
1 day, 1 hour ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
1 minute ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
1 day, 14 hours ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
1 day, 7 hours ago -
Limited account permission error related to Windows Update
by
gtd12345
2 days, 3 hours ago -
Another test post
by
gtd12345
2 days, 3 hours ago -
Connect to someone else computer
by
wadeer
1 day, 22 hours ago -
Limit on User names?
by
CWBillow
2 days, 1 hour ago -
Choose the right apps for traveling
by
Peter Deegan
1 day, 15 hours ago -
BitLocker rears its head
by
Susan Bradley
23 hours, 4 minutes ago -
Who are you? (2025 edition)
by
Will Fastie
22 hours, 1 minute ago -
AskWoody at the computer museum, round two
by
Will Fastie
1 day, 17 hours ago -
A smarter, simpler Firefox address bar
by
Alex5723
2 days, 13 hours ago -
Woody
by
Scott
2 days, 23 hours ago -
24H2 has suppressed my favoured spider
by
Davidhs
22 hours, 41 minutes ago -
GeForce RTX 5060 in certain motherboards could experience blank screens
by
Alex5723
3 days, 13 hours ago -
MS Office 365 Home on MAC
by
MickIver
3 days, 7 hours ago -
Google’s Veo3 video generator. Before you ask: yes, everything is AI here
by
Alex5723
4 days, 3 hours ago -
Flash Drive Eject Error for Still In Use
by
J9438
22 hours, 25 minutes ago -
Windows 11 Insider Preview build 27863 released to Canary
by
joep517
4 days, 22 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.