Print selection code doesn

szakharov7723

Board Regular
Joined
Jun 22, 2018
Messages
85
Office Version
2019
Platform
Windows
Hello, I am trying to create a code to automatically select the range (that can vary horizontally) and print it.
I tried to use this code, but it prints only 1 page regardless the amount of pages needed to print all data in range.
And I don't even understand why it limits it to 1 page.

Code:
Sub PrintSelection()
'
    Range("A1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.PrintOut
End Sub
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

szakharov7723

Board Regular
Joined
Jun 22, 2018
Messages
85
Office Version
2019
Platform
Windows
Re: Print selection code doesn't work properly

Well I didn't finish the post, but stupid Tab triggered with no cursor and selected the post thread while I was pressing Enter. In general question in body is the same I just didn't finish the title and now I cannot edit it.
 

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
16,692
Re: Print selection code doesn't work properly

Have you tried stepping through your code to see if it selects the entire range you want to print? If it doesn't, here's an alternative you can try:
Code:
Sub PrintSelection()
ActiveSheet.PageSetup.PrintArea = Selection.Address
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
End Sub
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
12,057
Office Version
365, 2010
Platform
Windows, Mobile
Re: Print selection code doesn't work properly

What happens with...

Code:
Sub PrintSelection()
    With ActiveSheet.PageSetup
        .PrintArea = ActiveSheet.Range("A1").CurrentRegion.Address
        .Zoom = 100
    End With
    ActiveSheet.PrintOut
End Sub
 

szakharov7723

Board Regular
Joined
Jun 22, 2018
Messages
85
Office Version
2019
Platform
Windows
Re: Print selection code doesn't work properly

Yes, I stopped the code before print and I see that it selects it.
 

szakharov7723

Board Regular
Joined
Jun 22, 2018
Messages
85
Office Version
2019
Platform
Windows
Re: Print selection code doesn't work properly

It would just print some blank pages (probably because I have invisible formuals there) And funniest thing... still will print only 1 page of real data ( which I have on more than 1 page of print)
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
12,057
Office Version
365, 2010
Platform
Windows, Mobile
Re: Print selection code doesn't work properly

By
It would just
do you mean it did just... when I tested it.... probably just the grammar but not reading right to me.
 
Last edited:

szakharov7723

Board Regular
Joined
Jun 22, 2018
Messages
85
Office Version
2019
Platform
Windows
Re: Print selection code doesn't work properly

not really, but it wouldn't change the meaning. So yes that's what happened
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
12,057
Office Version
365, 2010
Platform
Windows, Mobile
Re: Print selection code doesn't work properly

but it wouldn't change the meaning
Yes it would, one implies that it hadn't been tested.

Afraid I have nothing to add currently as the code I posted printed out 3 pages with my data so unless you can provide any other info I don't know why it isn't printing the full area.
 
Last edited:

szakharov7723

Board Regular
Joined
Jun 22, 2018
Messages
85
Office Version
2019
Platform
Windows
Re: Print selection code doesn't work properly

or gives the outcome of what will happen if you execute this code
 

Forum statistics

Threads
1,089,617
Messages
5,409,358
Members
403,260
Latest member
ssauk

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top