Hi Shane,
Yesterday you post this to me (below) and I created a table with a range of
"A1:I6".
In row 1 starting from A1 I have these titles:
Team Play Win Draw Lose GF GA GD Points
In column A starting from A2 I have These names:
Roma
Milan
Lazio
Bari
Siena
The range I want to sort is "A2:I6".
I also attached the code you gave me, but when I post a result and for
example the points increase, a window is coming up with Compile error and
Syntax error. Why?
Thanks.
Regaring posting the whole file - I don't know what works best for that,
others here at the site could tell you.
There is no built-in feature to sort your data automatically. However, if
you want the sort to occur whenever you change or enter data in the important
columns -
1. First record the steps necessary to do the sort on you data. Then attach
the code to a Sheet_Change event.
Here is an example:
the range F2:I6 is my sample range where if an entry is changed the sort
reoccurs automatically. F2 because row 1 is titles and F is the first column
what something relevant could change. I6 you will need to adjust to include
as many rows as you want to trigger the auto sort. I2, F2 and H2 are the
Points, GF and GD columns. "A1:I6" is the entire sort range including the
titles. Again you will need to adjust that to fit your situation.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim isect As Range
Set isect = Application.Intersect(Target, Range("F2:I6"))
If Not isect Is Nothing Then
With ActiveSheet
With .Sort.SortFields
.Clear
.Add Key:=Range("I2"), _
SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:=xlSortNormal
.Add Key:=Range("H2"), _
SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:=xlSortNormal
.Add Key:=Range("F2"), _
SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:=xlSortNormal
End With
With .Sort
.SetRange Range("A1:I6")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
End If
End Sub