I have VBA code to auto-sort a league table.
My code is:
Option Explicit
Public Sub SortAll()
SortAAA
SortAA
SortA
End Sub
Sub SortAAA()
SortDivision Range("C6:P9"), Range("I6:I9")
End Sub
Sub SortAA()
SortDivision Range("C13:P17"), Range("I13:I17")
End Sub
Sub SortA()
SortDivision Range("C21:P24"), Range("I21:I24")
End Sub
Sub SortDivision(TotalRange As Range, KeyRange As Range)
With Me.Sort
.SortFields.Clear
.SortFields.Add _
Key:=KeyRange, _
SortOn:=xlSortOnValues, _
Order:=xlDescending, _
DataOption:=xlSortNormal
.SetRange TotalRange
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
The formula in the range column that dictates the sort is:
=IFERROR(F6/(F6+G6),".000")
The sort works perfectly when the standard part of the formula is able to be used:
But when there is an error (this is because that particular team have not yet played a fixture so far this season), everything else sorts correctly and all teams that have not yet played and require the =IFERROR are sat at the top of the pile which is causing issues with the other stats in the league table.
Any suggestions of how I can get the IFERROR teams to be included in the auto-sort? They are displaying the correct value from the formula however, not the correct playing in the league which means other formulas are now referring to the incorrect cells.
Thanks
Bookmarks