+ Reply to Thread
Results 1 to 6 of 6

Auto sort alphabetically using basic macro

  1. #1
    Registered User
    Join Date
    09-17-2012
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Smile Auto sort alphabetically using basic macro

    Hello,
    I have scoured this and other excel forums looking for a simple macro code I can drop into my excel document to auto sort alphabetically based on a column, but have been unsuccessful. I have attached my worksheet to provide context to my question.

    All I need is a macro that auto sorts all the rows alphabetically (descending) based on column C ("General Topic Categories") on sheet 1. Ideally the auto sort would occur once all the data in a row has been entered (i.e. column L), but I would be fine if it auto sorted after data was entered in column C in sheet 1. Also note that this will be be growing document, so the number of rows will always be increasing. It should be obvious but I don't want the headers sorted, so the first cell that should be alphabetized will be C2

    I know this can easily be done using the sort function, but I will not the one imputing the data and the individual in charge would like it auto sorted.

    Thank you in advance for your help

    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Auto sort alphabetically using basic macro

    Try this code in the Sheet1 module:
    Please Login or Register  to view this content.
    Post responsibly. Search for excelforum.com

  3. #3
    Registered User
    Join Date
    09-17-2012
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Auto sort alphabetically using basic macro

    Hello Chippy
    Thanks for the help, but unfortunately it's not working Also, not every cell in a row will be populated. Any additional help would be greatly appreciated. In reality, and to make things easier, I just need the rows to auto sort alphabetically based on data in column C.

    Thanks

  4. #4
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Auto sort alphabetically using basic macro

    Try deleting the "And Application.WorksheetFunction.CountA(Range("A" & Target.Row & ":L" & Target.Row)) = 12". Then the sort will occur after column L has been entered, regardless of any other cells on the row.

  5. #5
    Registered User
    Join Date
    09-17-2012
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Auto sort alphabetically using basic macro

    Hello Chippy,
    I GOT IT TO WORK! Thank you so much. I actually changed the code a tiny bit so that the sorting occurs when data is entered into column C (so it now says "If Target.Column = 3"). One final question, is there a way so the screen/selected cell moves with the recently alphabetized row? Currently, when data is entered into column 3 everything get alphabetized (which is great), but the selected cell stays at the bottom. I would like the selected cell to move with its row. My concern is that if there is a lot of rows, the row you are entering data into could get lost. Thanks

  6. #6
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Auto sort alphabetically using basic macro

    In order to know which row the input cell (currently selected cell in column C) has moved to after the sort, a little trick is needed. A temporary 'marker' is put in a spare column cell (I've used M) of the input row, and after the sort we look for the marker on its new row and select the C cell on that row. Here is the new code:
    Please Login or Register  to view this content.

+ 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