+ Reply to Thread
Results 1 to 9 of 9

Set Print Area macro Code

  1. #1
    Registered User
    Join Date
    05-31-2012
    Location
    Dhaka, Bangladesh.
    MS-Off Ver
    Excel Office 365
    Posts
    99

    Question Set Print Area macro Code

    Hi,
    I need a macro code. "TOTAL VALUE" will appear in column A but in different row, some times 28, or 29 or 26 or 30 even 40.Is there any macro code so that macro will set print area till the row containing "TOTAL VALUE", so its mean print area will be set column A to E and row will be 1 to till "TOTAL VALUE" containing row. I attached a sample file to make clear my query. I have code but row is fixed. But my requirement is different in case of row. Please help me for this macro code.

    Sub Set_Print_Area()
    '
    ' Set_Print_Area Macro
    '
    ActiveSheet.PageSetup.PrintArea = Range("A1", Range("E40").End(xlUp)).Address

    End Sub


    Thanks
    roman
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,433

    Re: Set Print Area macro Code

    Change the "E40" to "E" & Rows.Count


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    05-31-2012
    Location
    Dhaka, Bangladesh.
    MS-Off Ver
    Excel Office 365
    Posts
    99

    Re: Set Print Area macro Code

    wow! it is working but i need to set area till "TOTAL VALUE" containing row not till last value

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,433

    Re: Set Print Area macro Code

    Ok, then maybe add .Offset(-4, 0)

  5. #5
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Set Print Area macro Code

    Hi romandotcom,

    Try this which accounts for no cell containing the text "TOTAL VALUE" as is the case with your attached workbook:

    Please Login or Register  to view this content.
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  6. #6
    Registered User
    Join Date
    05-31-2012
    Location
    Dhaka, Bangladesh.
    MS-Off Ver
    Excel Office 365
    Posts
    99

    Re: Set Print Area macro Code

    Quote Originally Posted by TMShucks View Post
    Ok, then maybe add .Offset(-4, 0)
    Hi TMShucks

    I didn't understand where i will add it, could please notify me??

  7. #7
    Registered User
    Join Date
    05-31-2012
    Location
    Dhaka, Bangladesh.
    MS-Off Ver
    Excel Office 365
    Posts
    99

    Re: Set Print Area macro Code

    Hi Robert

    I attached a sample file again, please where i made the error, i couldn't.
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Set Print Area macro Code

    Hi romandotcom,

    To fix my code, simply change this line of code...

    Please Login or Register  to view this content.
    ...to this:

    Please Login or Register  to view this content.
    Regards,

    Robert

  9. #9
    Registered User
    Join Date
    05-31-2012
    Location
    Dhaka, Bangladesh.
    MS-Off Ver
    Excel Office 365
    Posts
    99

    Re: Set Print Area macro Code

    thank u so much, its working

+ 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.6.0 RC 1