+ Reply to Thread
Results 1 to 6 of 6

Thread: How to Clean Up this easy Range Selection Syntax

  1. #1
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    242

    Question How to Clean Up this easy Range Selection Syntax

    I know that this is a simple request - but I am having some trouble as I am still new to this.

    Isn't there an easier way to perform this action?
        Range("A1", Range("B500").End(xlUp)).Select
        Selection.Resize(Selection.Rows.Count, Selection.Columns.Count + 1).Select
        ActiveSheet.PageSetup.PrintArea = Selection.Address
    Thanks and sorry in advance.
    Last edited by clemsoncooz; 02-09-2012 at 03:25 PM.

  2. #2
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: How to Clean Up this easy Range Selection Syntax

    Should I just stay with it then. It doesnt pose any problems....just didnt know if I should clean it up since most of the advice I receive is "don't use select"

  3. #3
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: How to Clean Up this easy Range Selection Syntax

    what about this
    ActiveSheet.PageSetup.PrintArea = Range("A1", Range("B500").End(xlUp).Offset(, 1)).Address
    Best Regards
    MaczaQ
    ---------------------------------------------------------------------------------------------------------------------------
    If you are satisfied with the solution(s) provided, please mark your thread as Solved
    If you are pleased with my answer consider to use the Scales icon to rate it - This way you will add me some reputation points ... thanks in advance.

  4. #4
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: How to Clean Up this easy Range Selection Syntax

    yea, yea thats what I was talking about. That does solve my question....but now that I run that code, I realize my question wasn't asked correctly because while your code is correct, it doesnt work correctly on my sheet because of the layout.

    The resulting print area is (2) rows off and here is why.

    I chose Column B because B31 to G33 is a merged cell. I am offsetting 1 column because I have data in G, but NOT H, and I need my print aread to extend to H. So when you offset 1 column from the merged cell of B31:G33, the result is H31. NOT H33, therefore it is off by (2) rows.

    Know how to fix?

  5. #5
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: How to Clean Up this easy Range Selection Syntax

    so try to use
    ActiveSheet.PageSetup.PrintArea = Range("A1", Range("B500").End(xlUp).Offset(2, 1)).Address
    or attach your workbook with dummy data to show me your sheet structure
    Best Regards
    MaczaQ
    ---------------------------------------------------------------------------------------------------------------------------
    If you are satisfied with the solution(s) provided, please mark your thread as Solved
    If you are pleased with my answer consider to use the Scales icon to rate it - This way you will add me some reputation points ... thanks in advance.

  6. #6
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: How to Clean Up this easy Range Selection Syntax

    Got it.

    Thank you so much for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0