+ Reply to Thread
Results 1 to 4 of 4

Can I sort a column automatically everytime I close a file

  1. #1
    Registered User
    Join Date
    06-07-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    7

    Can I sort a column automatically everytime I close a file

    Hi,

    I have one file collecting data from another spreadsheet using Lookup functions. For this to work the 'database' of information always needs to be in numerical order, which is fine. However I have a few people adding/editing data within this spreadsheet and can therefore not guarantee that it will always be left in numerical order.

    I was wondering if there is a way of automating this as the file is closed? ie every time the database is closed column A is sorted A to Z?

    Any ideas? I am a novice when it comes to any macros but I'm sure one of you genius's can do this!!

    Thanks

    Jim

  2. #2
    Forum Contributor
    Join Date
    01-20-2012
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: Can I sort a column automatically everytime I close a file

    1 open the VB Editor.

    2 View the Project Explorer if not already visible.

    3 Right click over the "ThisWorkbook" object. Select 'View code'.

    4 In the Code page, add the following code...
    Please Login or Register  to view this content.
    Last edited by rkey; 06-07-2012 at 09:19 AM. Reason: forgot tags

  3. #3
    Registered User
    Join Date
    06-07-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Can I sort a column automatically everytime I close a file

    Hi rkey,

    Thanks for your help.

    I have done as suggested, and when I close the file something appears to happen on the data (the data in col a flashes), but nothing actually gets sorted.

    Any suggestions?

    Thanks

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Can I sort a column automatically everytime I close a file

    The posted solution is missing one line of code:

    Please Login or Register  to view this content.
    The posted solution will sort only column A. That sounds like what you said you wanted but is that the only data in your worksheet? Or do you need to sort a lot of columns of data using column A as the sort key?

    By the way, for the worksheet reference I would suggest deleting "ActiveWorkbook." (including the dot). In this case it probably won't cause an issue but in general depending on ActiveWorkbook (or Active anything) is risky since you as the coder don't really know for certain what is going to be active at any given time, and if code changes later it's even stickier.
    Last edited by 6StringJazzer; 06-07-2012 at 11:11 AM. Reason: Syntax error! Need a dot in front of SortFields
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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