+ Reply to Thread
Results 1 to 10 of 10

Macro to Print Selection

  1. #1
    Registered User
    Join Date
    11-20-2008
    Location
    England
    MS-Off Ver
    2007
    Posts
    65

    Macro to Print Selection

    HI all,

    I seem to be getting myself into a complete muddle as was wondering if someone to help me with a Printing problem.

    On the attached sample, i'm trying to write a macro to print the selection but only print where the status is "Active" to the ned of the selection. However, the spreadsheet is changing on a daily basis i.e. new lines being added and lines being taken off.

    So, to take potential of user error out i wanted a macro to print the "active" selection.

    Can anyone please help me get started !
    Attached Files Attached Files

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436
    Will records be a mix of Active and non active?
    In which case you would want rows ignored when printing. If this is the case you will need to filter the data before printing. You can use the Workbook_BeforePrint event, in Thisworkbook object, to apply autofilter.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    11-20-2008
    Location
    England
    MS-Off Ver
    2007
    Posts
    65
    They should be all active, as non active will be cut & pasted to another sheet.

    So, in other words everything on sheet1 needs printing down to the last active cell.
    Sorry, i forgot to mention there will be If(ISblank() formulaes in some columns, so then not to include these in the selection.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436
    A little confused. Where would those formula be?

    Currently the sheet only prints the information included in the sheet.

    Is it that after deleting/moving rows what excel things of as the last row is not the last row of data but the row that previously had data?

  5. #5
    Registered User
    Join Date
    11-20-2008
    Location
    England
    MS-Off Ver
    2007
    Posts
    65
    Sorry, for not making myself clear. I hope the following helps;

    ok, so the spreadsheet is for example 500 rows long and from Col a to o.

    there are formulaes (starting IF(ISBLANK) in C, K,L,N & O. Therefore, a user goes to the bottom of the sheet and enters into the rest of the cells starting at col A and putting the status to "Active".

    They will also match off any rows where credit amount = debit amount and put the status to "closed", these (via a macro) will be cut & pasted to
    'Sheet2' and the rows deleted.

    So, the print range is continually changing.

    I was then thinking whether a macro could be written to select this ever changing range and Printing it.

    Is it possible ?

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436
    How about locating the last occurance of active and using that row number.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-20-2008
    Location
    England
    MS-Off Ver
    2007
    Posts
    65
    The code didn't do anything!

    But, i was thinking would a dynamic range work?

    So the dynamic range is continually picking up the range when it changes but then how would i incorporat into a macro ?

    Or am i talking gibberish?

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436
    The must have done something, even if it only errored.

    Yes you can set the PrintArea to a named range.
    But you are still left with the problem of identifying the last row some how.

  9. #9
    Registered User
    Join Date
    11-20-2008
    Location
    England
    MS-Off Ver
    2007
    Posts
    65
    Sorry Andy it does work,

    I've done a few tests, i.e. adding rows and deleting rows and the macro picks up the last cell which is populated and is not picking up any cells that are Blank or with ISblank formula in.

    So, now how do i link all this in to a macro that prints this selection over 1, 2, 3 etc.. pages ?

    as i'm not sure how to write the macro

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436
    Simplest thing is a Button which would run the following

    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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