ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Automatic Alphabetize (https://www.excelbanter.com/excel-discussion-misc-queries/87642-automatic-alphabetize.html)

J Brydle

Automatic Alphabetize
 
Hi everyone. I need a little help.

I have a spreadsheet with a name column, and 4 or 5 other columns in each
record associated with the name. I want to have these records sorted
alphabetically by the name either as they are being added, or when the
spreadsheet is saved. I know the sort button works just fine, but this is a
request from the boss, and the boss wants it to be automatic. Is there any
way to do this, or do I just have to drill it home that the sort button is
good enough?

Using Office 2003.

Thanks a lot,
JBrydle

Miguel Zapico

Automatic Alphabetize
 
You may record a macro with what you do for sorting, and then edit that macro
in the Visual Basic Editor (Alt+11) and move the code to the
Workbook_BeforeSave event (open "ThisWorkbook" from the project explorer,
select "workbook" in the (General) dropdown and "BeforeSave" in the
(Declarations) dropdown)
That will launch that code before the workbook is saved, check if the
recorded macro behaves as expected, you may need to tweak the code.

About doing it after every row added automatically, there is an event in the
worksheet called Worksheet_change, that will be executed after every change.
You may need a lot of tweaking of the code to make it more useful that
annoying with that event, I would keep the sort button for that case (or
assign the sort macro to a custom button, your boss may like it better, who
knows)

Hope this helps,
Miguel.

"J Brydle" wrote:

Hi everyone. I need a little help.

I have a spreadsheet with a name column, and 4 or 5 other columns in each
record associated with the name. I want to have these records sorted
alphabetically by the name either as they are being added, or when the
spreadsheet is saved. I know the sort button works just fine, but this is a
request from the boss, and the boss wants it to be automatic. Is there any
way to do this, or do I just have to drill it home that the sort button is
good enough?

Using Office 2003.

Thanks a lot,
JBrydle


Dominic

Automatic Alphabetize
 
LOL. What the boss wants...

You could creat a macro and tie it to the workbook save event. Not sure if
this is the best way to do it but...

Sub SortByName()
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A1").Select
End Sub

Put this code into your Workbook:BeforeSave area in the Visual Basic Editor.

This code assumes that the list starts in cell A1 and that the name column
is column A.

HTH.

"J Brydle" wrote:

Hi everyone. I need a little help.

I have a spreadsheet with a name column, and 4 or 5 other columns in each
record associated with the name. I want to have these records sorted
alphabetically by the name either as they are being added, or when the
spreadsheet is saved. I know the sort button works just fine, but this is a
request from the boss, and the boss wants it to be automatic. Is there any
way to do this, or do I just have to drill it home that the sort button is
good enough?

Using Office 2003.

Thanks a lot,
JBrydle



All times are GMT +1. The time now is 04:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com