Macro to print

CalRich1023

New Member
Joined
Mar 15, 2021
Messages
47
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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Osvaldo Palmeiro

Well-known Member
Joined
Feb 24, 2009
Messages
635
Office Version
  1. 365
Platform
  1. Windows
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
 
Solution

CalRich1023

New Member
Joined
Mar 15, 2021
Messages
47
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,129,452
Messages
5,636,340
Members
416,914
Latest member
DWC199

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
Top