VBA to sort list automatically in alphabetical order

R

roniaelm

Hi,

I am using a VBA to automatically update a source list I am using for
my data validation list as explained on the Ozgrid.com website:

http://www.ozgrid.com/Excel/excel-validation-list-update.htm

This allows the list to be automatically updated from the cells that
contain the data validation list - rather then having to go to the
source list itself. However, once the list is updated I would like it
to be automatically sorted by alphabetical order to save me time. Does
anyone know a VBA code for sorting in alphabetical order? My list is
on a seperate worksheet in column A.

Thanks for your help!
 
M

Mike H

Hi,

Make this the last line of the routine that updates the list

Columns("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending

Mike
 
R

roniaelm

Hi,

Make this the last line of the routine that updates the list

Columns("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending

Mike

Hi Mike,

Thanks for your help!
The code worked, but I forgot to mention earlier my source list is on
another sheet - which I have named Data List.
Is there a way of making it sort the list on this sheet? As at the
moment it sorted the column A on the sheet where I have my data
validation.

Thanks!
 
M

Mike H

Hi,

Do it like this

With Sheets("Data List")
..Columns("A:A").Sort Key1:=.Range("A1"), Order1:=xlAscending
End With


Mike
 
R

roniaelm

Hi,

Do it like this

With Sheets("Data List")
.Columns("A:A").Sort Key1:=.Range("A1"), Order1:=xlAscending
End With

Mike

Hi Mike,

Thanks that works!!
Sorry to be a pain - my knowledge in VB is very limited.
I have one more probelm. My data starts from A2. A1 is a heading.
I have been trying to make it to sort from A2 but it is not working.
Do you have any suggestions??

Thanks!
 
D

Dave Peterson

Add:

Header:=xlyes

To your sort statement.

..Columns("A:A").Sort Key1:=.Range("A1"), Order1:=xlAscending, header:=xlyes
 
R

roniaelm

Add:

Header:=xlyes

To your sort statement.

.Columns("A:A").Sort Key1:=.Range("A1"), Order1:=xlAscending, header:=xlyes










--

Dave Peterson- Hide quoted text -

- Show quoted text -

Thanks soo much! That worked!!!
 

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