×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Excel set print area onclick

Excel set print area onclick

Excel set print area onclick

(OP)
Hi guys I returning to this after 15 yrs out and my memory is poor. So any help would be fantastic.

I have a button to select a range and print.

Private Sub cmdbtnPrint_Click()
ActiveSheet.Select
Range("A3:F21").Select
ActiveSheet.PageSetup.PrintArea = "A3:F21"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True

End Sub

I need to have the end range as a variable ie F21 needs to look and find the last row to cell 21
Thanks

RE: Excel set print area onclick

If your table is the ONLY thing on the sheet AND you properly DELETE to remove unused cells beside and beneath your table, then UsedRange can be used.

Alternativly, as long as you have a Proper Table (ONE row of headings, NO empty rows within your table, no other non-table data in cells contiguous with the table) then you can use CurrentRegion.

The latter would be my suggestion..

CODE

Private Sub cmdbtnPrint_Click()
ActiveSheet.Select
Range("A3”).CurrentRegion.Select
ActiveSheet.PageSetup.PrintArea = Selection.Address
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Excel set print area onclick

(OP)
thanks guys

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close