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.![]()
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.![]()
Welcome to the forum. :-)
Can you upload an example workbook. It would help us build the macro for you.
Thanks,
Bonny Tycoon
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
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
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
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks