Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Print selection code doesn
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Jun 2018
    Posts
    63
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Print selection code doesn

    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

  2. #2
    Board Regular
    Join Date
    Jun 2018
    Posts
    63
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default 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.

  3. #3
    MrExcel MVP
    Join Date
    May 2009
    Posts
    16,590
    Post Thanks / Like
    Mentioned
    39 Post(s)
    Tagged
    9 Thread(s)

    Default 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
    Joe

    When I was a young man I knew everything. Now that I'm older, I realize I know very little, and what I do know, I tend to forget!

  4. #4
    Board Regular MARK858's Avatar
    Join Date
    Nov 2010
    Location
    Southern England
    Posts
    11,242
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    2 Thread(s)

    Default 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
    Test VBA on a copy of your data (remember you can't normally reverse the action)

    Please follow the forum Rules and Guidelines & please use Code tags around your code i.e. [CODE]your code[/CODE]

    To post a screenshot try one of these links
    MrExcel HTML Maker, RoryA addin (Win & Mac) or Borders-Copy-Paste

  5. #5
    Board Regular
    Join Date
    Jun 2018
    Posts
    63
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Print selection code doesn't work properly

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

  6. #6
    Board Regular
    Join Date
    Jun 2018
    Posts
    63
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default 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)

  7. #7
    Board Regular MARK858's Avatar
    Join Date
    Nov 2010
    Location
    Southern England
    Posts
    11,242
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    2 Thread(s)

    Default 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 by MARK858; Oct 16th, 2019 at 05:13 PM.
    Test VBA on a copy of your data (remember you can't normally reverse the action)

    Please follow the forum Rules and Guidelines & please use Code tags around your code i.e. [CODE]your code[/CODE]

    To post a screenshot try one of these links
    MrExcel HTML Maker, RoryA addin (Win & Mac) or Borders-Copy-Paste

  8. #8
    Board Regular
    Join Date
    Jun 2018
    Posts
    63
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Print selection code doesn't work properly

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

  9. #9
    Board Regular MARK858's Avatar
    Join Date
    Nov 2010
    Location
    Southern England
    Posts
    11,242
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    2 Thread(s)

    Default 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 by MARK858; Oct 17th, 2019 at 09:14 AM.
    Test VBA on a copy of your data (remember you can't normally reverse the action)

    Please follow the forum Rules and Guidelines & please use Code tags around your code i.e. [CODE]your code[/CODE]

    To post a screenshot try one of these links
    MrExcel HTML Maker, RoryA addin (Win & Mac) or Borders-Copy-Paste

  10. #10
    Board Regular
    Join Date
    Jun 2018
    Posts
    63
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Print selection code doesn't work properly

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

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •