ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   AUTOSORTING (https://www.excelbanter.com/excel-discussion-misc-queries/126184-autosorting.html)

FARAZ QURESHI

AUTOSORTING
 
Can any1 help me with telling me a macro to autosort a list right after I
make a new entry in a new row or within the array

Dave Peterson

AUTOSORTING
 
Personally, I wouldn't sort my data after I made an entry. If I made a typo,
who knows where that row would go.

But you can make sorting the data easier...

In xl2003, you can apply data|filter|autofilter to the range and use the
dropdown arrow to sort your data.

Debra Dalgleish has a technique at her site that adds invisible rectangles in
the headers and then sorts the data by that field when you click on one of those
rectangles.

http://contextures.com/xlSort02.html

FARAZ QURESHI wrote:

Can any1 help me with telling me a macro to autosort a list right after I
make a new entry in a new row or within the array


--

Dave Peterson

Chip Pearson

AUTOSORTING
 
I agree with Dave's opinion about not autosorting, but if you want to
proceed with despite his warnings, here's the code to do it. Put the
following code in the worksheet module (right-click the worksheet tab that
you want to sort) and paste in the following code. Change SORT_COLUMN to
the column number that you will be enter data into. Change header:=xlGuess
to either xlNo or xlYes, depending on whether your column has a header that
should not be sorted.


Private Sub Worksheet_Change(ByVal Target As Range)
Const SORT_COLUMN = 1 '<<<< CHANGE AS NEEDED
If Target.Columns.Count 1 Then
Exit Sub
End If
If Target.Column = SORT_COLUMN Then
Application.EnableEvents = False
Me.UsedRange.Sort key1:=Me.Cells(1, SORT_COLUMN),
order1:=xlAscending, _
header:=xlGuess
Application.EnableEvents = True
End If
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"FARAZ QURESHI" wrote in message
...
Can any1 help me with telling me a macro to autosort a list right after I
make a new entry in a new row or within the array





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

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