Macros - Only Print Rows With Data Plus Header

Laurinda

New Member
Joined
Aug 23, 2011
Messages
16
Hi,
I'm trying to update a macros for a print button. I'm trying to only print a row if there is data in column J. This macros is working great for that, but I also have a header that I would like printed (rows 1 to 15) which includes a picture of the logo. Does anyone know how I could update this macros to include the header with picture in the print? Thanks in advance! :)

Sub Button7_Click()
'prints rows of data, will not print rows if column J is blank
Application.ScreenUpdating = False
Range("J:J").EntireRow.Hidden = False
Range("J:J").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Range("J:J").EntireRow.Hidden = False
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try:
Untested

Code:
Sub Button7_Click()
'prints rows of data, will not print rows if column J is blank
Application.ScreenUpdating = False
Range("J:J").EntireRow.Hidden = False
Range("J16:J1000").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Range("J:J").EntireRow.Hidden = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0
This will set your print titles and print area as you have described them in your post and then print out.
Code:
Sub Button7_Click()
Dim lR As Long
lR = Range("J" & Rows.Count).End(xlUp).Row
Intersect(Rows("16:" & lR), ActiveSheet.UsedRange).Name = "Print_Area"
Rows("1:15").Name = "Print_Titles"
Application.ScreenUpdating = False
Range("J16:J" & lR).EntireRow.Hidden = False
Range("J16:J" & lR).SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Range("J:J").EntireRow.Hidden = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0
This works great! Thank you very much! I am coming across another problem though... This excel spreadsheet is protected & the macros works great if it's not protected, but as soon as I protect it, it gives me the following error:

Run-time error '1004'"
Unable to se the Hidden property of the Range class

Do you know how to get around this?
 
Upvote 0
You need to unprotect the sheet then reprotect it

At the beginning put

ActiveSheet.Unprotect "Insert Password Here"

And at the End Put

ActiveSheet.Protect "Insert Password Here"
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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