VBA Print - combining ranges

Jasesair

Active Member
Joined
Apr 8, 2015
Messages
282
Office Version
  1. 2016
I have the below VBA that is printing the ranges desired but on separate pages. Does anyone know how I can adjust this so it prints together? Hoping this makes sense - I'm basically wanting to select the columns I want in a table and print the table.

VBA Code:
Sub PrintManualEntry2021()
Sheets("2021").Range("a8:c77,ht8:ia77").PrintPreview
End Sub

Not sure if it's possible, but I'd also love the VBA to identify the last row in column C with any data and just print the full range down to that row.

Thanks heaps!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Perhaps use VBA to ...
hide columnsa D:HS
print A8:IA77
unhide columns D:HS
 
Upvote 0
Thanks Yongle, that thinking was exactly what I needed!

My table data is in rows 8:77. Any idea how to adjust to only print down as far as needed? ie. users will add new data into the next available row so there might be hypothetically rows 50:77 with no data. If there's some way to look down row C to the last entry and only print the range enough to include that last entry, that would be fantastic.
 
Upvote 0
how about

VBA Code:
Sub PrintManualEntry2021()
    Dim printRng As Range, hideRng As Range
    With Sheets("2021")
        Set printRng = .Range("A8:IA" & .Cells(.Rows.Count, "C").End(xlUp).Row)
        Set hideRng = .Range("D:HS").EntireColumn
    End With
        
    hideRng.Hidden = True
    printRng.PrintPreview
    hideRng.Hidden = False
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,470
Messages
6,124,993
Members
449,201
Latest member
Lunzwe73

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