Automatic Alphabetical Sort

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.
 
R

ryguy7272

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---
 
C

Chip Pearson

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)
 
C

CG

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top