+ Reply to Thread
Results 1 to 9 of 9

Auto Sort/Print Macro

  1. #1
    Registered User
    Join Date
    01-27-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Auto Sort/Print Macro

    I have a document with 4 rows that I would like to automatically sort in Alphabetical (or numerical) order and then print. These docs are updates 3 times a day and it takes a while to open each one, sort and then print. I would like to know if there is a macro that would sort and print right when I open the document? Is this possible? Thanks for the help!

  2. #2
    Registered User
    Join Date
    04-24-2010
    Location
    MA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Auto Sort/Print Macro

    Yes. Could you please upload a sample document with dummy data so that we know what the range is that needs to be referenced in the macro for the sorting? Our all of the docs designed to use the same range of cells, or do they vary?

  3. #3
    Registered User
    Join Date
    01-27-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Auto Sort/Print Macro

    Here is an example of one of the documents. It is a list of Inventory with amount, cost, and total. I want them to be sorted alphabetically and then printed 3 times a day automatically. It is a list of over 5,000 rows in my actual data set though.

    Thanks a lot!
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    04-24-2010
    Location
    MA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Auto Sort/Print Macro

    Is this what you want? The workbook automatically sorts the first column alphabetically when it is opened and then runs the print function. If this is what you want, I can show you how to apply the macro to your workbooks, assuming they are all 4 columns.

    Your initial question was whether each file could automatically sort and print when you opened it. Your last message implies to me that you would like the entire process to occur automatically: open, sort, print. If that's the case, you would need macro software to tell your operating system to open the files at scheduled times. That is not something that could be done within Excel itself.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    01-27-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Auto Sort/Print Macro

    Yeah I would like it to be opened by me and then sort and print. I don't need to use task scheduler or anything like that. How would you go about applying this macro to my workbooks? Thanks again for the help

  6. #6
    Registered User
    Join Date
    04-24-2010
    Location
    MA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Auto Sort/Print Macro

    Here is a link to a video showing you how to apply the macro:

    http://www.youtube.com/watch?v=zXpMS0deYyI

    Here is the macro so that you can copy and paste it:

    Private Sub Workbook_Open()
    Worksheets("Sheet1").Range("A:D").Sort Key1:=Worksheets("Sheet1").Range("A1"), Order1:=xlAscending, Header:=xlYes
    ActiveSheet.PrintOut
    End Sub

    Hope this helps!

  7. #7
    Registered User
    Join Date
    01-27-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Auto Sort/Print Macro

    Thanks so much for your help! Amazing!

    One more question (Sorry)

    If I had a massive merged header at the top and my info started at like row 10 (like in this example) , how would that change the code? Also, if my tab isn't called Sheet1 (its called "Inventory") would I need to change that as well? Thanks again for all your help!!

  8. #8
    Registered User
    Join Date
    04-24-2010
    Location
    MA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Auto Sort/Print Macro

    You are correct that the code would need to be modified for the name of the spreadsheet and the range of cells. Here is an example of how you would change it.

    Private Sub Workbook_Open()
    Worksheets("Inventory").Range("A10:D10000").Sort Key1:=Worksheets("Inventory").Range("A10"), Order1:=xlAscending, Header:=xlYes
    ActiveSheet.PrintOut
    End Sub

    The two references to sheet 1 are now Inventory. The reference to the range of cells should begin with the row where the first product is listed. The end of the range can be any row after the first row. I used 10000 to allow for larger lists. You mentioned 5500 items, so 10000 should be sufficient.

  9. #9
    Registered User
    Join Date
    01-27-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    12

    {solved}

    Thanks a lot for all the 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.6.0 RC 1