Auto Sort

  • Thread starter Thread starter denv
  • Start date Start date
D

denv

Is it possible to sort a group automatically so that every time the data
changes it automatically sorts by a certain column?
 
Right click on the Sheet tab and select View Code. Set dropdowns to
"Worksheet" and "Change".

Add code.
If you want the entire sheet (Cells.Select) to be sorted, then try the code
below. Otherwise, instead of "Cells.Select", specify the specific cell
range [ex - Range("A1:D4").Select ].

Cells.Select
Selection.Sort Key1:=Range("C1"), Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A1").Select
 
denv,

Don't you Excel Tip people believe in using names? ;-)

You can use the worksheet change event to do it: copy the code below,
right-click on the worksheet tab and select view code, and paste the
code into the window that appears.

The code will sort the current region around A1, descending on column
A (with headers), any time a cell in the current region of A1 is
changed.

HTH,
Bernie

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1").CurrentRegion) Is Nothing Then Exit
Sub
Application.EnableEvents = False
Range("A1").CurrentRegion.Sort _
Key1:=Range("A2"), _
Order1:=xlDescending, _
Header:=xlYes
Application.EnableEvents = True
End Sub
 
Back
Top