Automatic Alphabetical Sort

  • Thread starter Thread starter CG
  • Start date Start date
C

CG

I have a vba form which adds a name to the bottom of the list. How so I make
that list of names automatically sort alphabetically.
 
Right click on the sheet of interest; paste this code into the window that
opens:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 And Target.Row >= 1 Then
Range("A1", Range("A1").End(xlDown)).Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End If
End Sub

May need a bit of modifying, btu this should be pretty darn close...

Regards,
Ryan---
 
You should disable events within the Change event before making any
changes. Otherwise, the Change event makes a change, that triggers
Change, which makes a change that triggers Change, as so on until you
run out of stack space.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
'''
' code
'''
Application.EnableEvents =True
End Sub

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
I am having an Compiled Error: Expected:expression error in the := of
the last 2 lines. What does this mean? Sorry I am new to VBA!
 
Back
Top