Print only rows when there is text inside

Takaishi

New Member
Joined
Sep 18, 2023
Messages
1
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hey all,

I am going crazy trying to do the following:

Fellow employees are working on a work related Excel sheet with columns from A2 to G2 (headers) and 103 rows. When adding text starting in row C3 up until G3 with a total of 103 rows, I want it to check if there is text in any of these rows and if so, keep it. If not, remove the complete row.

All of this should happen when clicking on a button called "Print", which I have already inserted. I have tried every possible code solution but I do not get it.

I would appreciate a push in the right direction, thanks!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Your post is a bit ambiguous: the title says to print only rows with text, but the description says to remove these rows and then print. I've coded for the former case.

Assign this macro to your "Print" button.

VBA Code:
Public Sub Print_Non_Blank_Rows()

    Dim hideRowsRange As Range, r As Long
    
    Set hideRowsRange = ActiveSheet.Range("C3:G105")
    
    'Hide empty rows
    
    For r = 1 To hideRowsRange.Rows.Count
        If Application.CountA(hideRowsRange.Rows(r)) = 0 Then hideRowsRange.Rows(r).EntireRow.Hidden = True
    Next
    
    ActiveSheet.PrintOut
    
    'Unhide empty rows
    
    For r = 1 To hideRowsRange.Rows.Count
        If Application.CountA(hideRowsRange.Rows(r)) = 0 Then hideRowsRange.Rows(r).EntireRow.Hidden = False
    Next
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,803
Messages
6,181,055
Members
453,014
Latest member
Chris258

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top