Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 7 of 7

Thread: Macro or code for Selecting the print area.

  1. #1
    Guest

    Default

    Hope I ask this properly.
    I have a dummy spreadsheet set up for the quoting Dept. Range for each can be small to all columns and 10000+ rows.

    I only want to print a specific range
    lets say B1:F1000. Basically I
    want to print to the last active cell in F
    which contains data .

    Is there coding that will examine a range and determine where the data ends, and I can then set the print area I desire?


  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,959
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    The easy way to go is setup the print area as A:F, or B:F and Excel will determine by itself the last used row.
    Regards,

    Juan Pablo González
    http://www.juanpg.com

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Mike
    Posts
    796
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    ThankJuan, I'll try it.

  4. #4
    Board Regular
    Join Date
    Feb 2002
    Location
    Mike
    Posts
    796
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Here's the code I used to set the print area for what I thought would work. It didn't. IT set the print area for all of A and all og G. I was hoping it would find the last cell in the last row that contained data.
    Which in my trial run was G48.

    Code:
    Application.Goto Reference:="R1C1"
    ActiveCell.Range("A:G").Select
    ActiveSheet.PageSetup.PrintArea = "$A:$G"
    ActiveCell.Select

    What did I do wrong?

    _________________


    [ This Message was edited by: Zac on 2002-02-21 08:36 ]

  5. #5
    Board Regular
    Join Date
    Feb 2002
    Location
    Georgia USA
    Posts
    569
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I think Juan was talking about going to file,page setup and seting the print area to A:F, not using a marco. Hope this helps

  6. #6
    New Member
    Join Date
    Feb 2002
    Location
    Washington State
    Posts
    33
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Sub setprintarea()
    Dim myrange As String
    myrange = Cells(Rows.Count, 6).End(xlUp).Address
    ActiveSheet.PageSetup.PrintArea = "$A$1:" & myrange
    End Sub
    This looks for the last used cell in the F column and sets the print area accordingly.

    Rick

  7. #7
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,959
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-02-21 08:24, Zac wrote:
    Here's the code I used to set the print area for what I thought would work. It didn't. IT set the print area for all of A and all og G. I was hoping it would find the last cell in the last row that contained data.
    Which in my trial run was G48.

    Code:
    Application.Goto Reference:="R1C1"
    ActiveCell.Range("A:G").Select
    ActiveSheet.PageSetup.PrintArea = "$A:$G"
    ActiveCell.Select

    What did I do wrong?
    What ? well, actually, you didn't (You selected a whole bunch of things you didn't need to, but.... Actually THAT works ! unless, you have some "invisible" cells, formulas that return a "". If that's the case then you'll print some extra pages.

    Try the macro proposed, that should work.
    Regards,

    Juan Pablo González
    http://www.juanpg.com

Some videos you may like

User Tag List

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
  •