+ Reply to Thread
Results 1 to 6 of 6

Alpabetically Auto Sort when new data is entered

Hybrid View

  1. #1
    Registered User
    Join Date
    08-03-2012
    Location
    meridian, id
    MS-Off Ver
    Excel 2007
    Posts
    3

    Alpabetically Auto Sort when new data is entered

    I would like the VB script code that will automatically alphabetize a column of names when a new name is entered at the bottom of the list. I have names in column A and associated data in columns B,C,D,E and F. Columns B and C are hidden. Thank you.

  2. #2
    Forum Contributor bonny24tycoon's Avatar
    Join Date
    04-02-2012
    Location
    Hell
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    405

    Re: Alpabetically Auto Sort when new data is entered

    Welcome to the forum. :-)

    Can you upload an example workbook. It would help us build the macro for you.
    Thanks,

    Bonny Tycoon


  3. #3
    Registered User
    Join Date
    08-03-2012
    Location
    meridian, id
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Alpabetically Auto Sort when new data is entered

    Here is a sample of the spreadsheet. There will be hundreds of names and the list will continue to grow infinitely. Thank you so much
    Attached Images Attached Images

  4. #4
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Alpabetically Auto Sort when new data is entered

    The problem you will run into with an autosort is WHEN to sort the field. For example, if you sort immediately after a new name is added, then you have to find the name to enter the corresponding data. Should the autosort trigger after the last field is entered? Is added by ALWAYS filled out?

    Try this code in the WORKSHEET MODULE:
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim r As Range
        
        Application.EnableEvents = False
        
        If Target.Row > 1 And Target.Column = 5 Then
            Set r = Range("A1").CurrentRegion
            r.Sort key1:=Range("A1"), order1:=xlAscending, header:=xlYes
        End If
        
        Application.EnableEvents = True
            
    End Sub

  5. #5
    Registered User
    Join Date
    08-03-2012
    Location
    meridian, id
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Alpabetically Auto Sort when new data is entered

    How about on save or exit. What is best.

    ---------- Post added at 06:18 PM ---------- Previous post was at 04:08 PM ----------

    Nothing happened when I input a new name. This is what I did.
    1. clicked "developer tab"
    2. clicked "Visual Basic"
    3. clicked "Insert Module"
    4 pasted the code
    5. added a new name

    I did not fill in the hidden columns as to emulate the way a user will enter new names. Did I do it right?
    Last edited by Cutter; 08-03-2012 at 04:46 PM. Reason: Removed whole post quote

  6. #6
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Alpabetically Auto Sort when new data is entered

    Marty,
    This code is meant to be in the Worksheet module, not in a general tab. In order to get there, right click on the sheet tab (at the bottom of the workbook, where you would normally choose between worksheets) and select VIEW CODE. Then paste the code in there

+ 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