Print range in excel

MarkDave

New Member
Joined
Mar 25, 2009
Messages
30
Office Version
  1. 365
Platform
  1. Windows
I've an excel worksheet with columns A5 - A2039 containing dates, i.e 16-Mar-2009 to 31-Dec-2014.

What I need is a print button, which when pressed will allow users to select the date ranges to be printed, (i.e from and to)

I currently have a print button with the code;

Private Sub Commandbutton1_Click()
ActiveWindow.SelectedSheets.Printout copies:=1, Collate:=True
End Sub

however, this just prints everything...i.e all 46 pages!!

any ideas? Sorry, new to this excel malarky...

Cheers!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hello and welcome to MrExcel.

Try this - you can type in the range or select it using the mouse:

Code:
Private Sub Commandbutton1_Click()
Dim r As Range
Set r = Application.InputBox("Select the range to print")
If r Is Nothing Then Exit Sub
With ActiveSheet
    .PageSetup.PrintArea = r.Address
    .PrintOut
End With
End Sub
 
Upvote 0
Excellent!

Thanks for this, looks good however it comes up with

"Run-time error '424':

Object required

any ideas?
 
Upvote 0
Oops!

Rich (BB code):
Private Sub Commandbutton1_Click()
Dim r As Range
Set r = Application.InputBox("Select the range to print", Type:=8)
If r Is Nothing Then Exit Sub
With ActiveSheet
    .PageSetup.PrintArea = r.Address
    .PrintOut
End With
End Sub
 
Upvote 0
Thanks very much, comes up with the same error if I press cancel instead of selecting the rangeand essing ok, but I can work around that...


Thanks again!
 
Upvote 0
This deals with the Cancel problem

Code:
Private Sub Commandbutton1_Click()
Dim r As Range
On Error Resume Next
Set r = Application.InputBox("Select the range to print", Type:=8)
On Error GoTo 0
If r Is Nothing Then Exit Sub
With ActiveSheet
    .PageSetup.PrintArea = r.Address
    .PrintOut
End With
End Sub
 
Upvote 0
any ideas how I can amend this to allow users to type in dates from and to, (namely the info I have in cells A5 - A2039?

Sorry to keep changing the goal posts here...
 
Upvote 0

Forum statistics

Threads
1,203,600
Messages
6,056,203
Members
444,850
Latest member
dancasta7

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