VBA - print based on the last row

Jasesair

Active Member
Joined
Apr 8, 2015
Messages
282
Office Version
  1. 2016
I'd like to adjust the below code to print only the rows needed. I'm wanting the print down to the last row in Column C that contains any data. All of my attempts so far have failed unfortunately. Any help would be much appreciated.

VBA Code:
Sub PrintManualEntry2021()
Application.ScreenUpdating = False
Worksheets("2021").Unprotect
Worksheets("2021").Columns("HT:IA").EntireColumn.Hidden = False
Worksheets("2021").Columns("D:DD").EntireColumn.Hidden = True
Worksheets("2021").Rows("4:4").EntireRow.Hidden = True

Sheets("2021").Range("a1:ia77").PrintPreview

Worksheets("2021").Columns("HT:IA").EntireColumn.Hidden = True
Worksheets("2021").Columns("D:DD").EntireColumn.Hidden = False
Worksheets("2021").Rows("4:4").EntireRow.Hidden = False
Worksheets("2021").Protect
Worksheets("2021").Calculate
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Maybe....

VBA Code:
    With Sheets("2021")
        .PageSetup.PrintArea = .Range("A1:IA" & .Range("C" & Rows.Count).End(xlUp).Row).Address
        .PrintPreview
    End With
 
Upvote 0
Actually, on second glance, it is now causing me some issues. Is there another option to PrintPreview that doesn't adjust the PrintArea? I am currently using a different PrintArea in other VBA for PDFing. It's thrown completely out with this VBA that's shifting the PrintArea.
 
Upvote 0
Try
VBA Code:
    With Sheets("2021")
       .Range("A1:IA" & .Range("C" & Rows.Count).End(xlUp).Row).PrintPreview
    End With
although personally I would just reset the PrintArea in the code as you will have to put a separate line with the range to do a PrintOut as it will revert to the set PrintArea once you have previewed.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,944
Messages
6,122,387
Members
449,080
Latest member
Armadillos

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