Macro to print

CalRich1023

New Member
Joined
Mar 15, 2021
Messages
48
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I was wondering if there is a way to create a macro (assigned to a button-I can do this part) to print all occupied cells on a sheet? I have a search page that will produce varying rows of results, and I was hoping for a quick way to just print the cells that have contents.

If it helps, I can define the width of the area from cells A1:K1, but the bottom (last row) of the data will vary depending on the search results.

Thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hello. Try this:
VBA Code:
Sub PrintActiveSheet()
 Dim LastRow As Long
  With ActiveSheet
   LastRow = .Cells(Rows.Count, "A").End(3).Row 'get the last row with contents in column A
   .PageSetup.PrintArea = "A1:K" & LastRow
   .PrintOut
  End With
End Sub
 
Upvote 0
Solution
Hello. Try this:
VBA Code:
Sub PrintActiveSheet()
Dim LastRow As Long
  With ActiveSheet
   LastRow = .Cells(Rows.Count, "A").End(3).Row 'get the last row with contents in column A
   .PageSetup.PrintArea = "A1:K" & LastRow
   .PrintOut
  End With
End Sub
This worked like a charm! Thank you so much!
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,172
Members
448,554
Latest member
Gleisner2

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