I would like to code the following in VBA, a function of signature
Public Function MySort( v as Variant) as Variant
that takes a variant v having names in its first columns and notes in its second, checks if it has two columns, throws an error if it hasn't, and if it has two rows, does the following : it sorts v's rows according to v's second column in decreasing, and then, inside a group of same note, sorts it alphabetically. For instance, the function MySort
will send the variant
A 14
D 3
B 14
E 3
C 3
to the variant
A 14
B 14
C 3
D 3
E 3
from teh OP's comment below
I have tried this, without success :
Public Function MySort(r As Range) As Range
Dim r1 As Range
Dim r2 As Range
Set r1 = r.Columns(1)
Set r2 = r.Columns(2)
r.Sort Key1:=r1, Order1:=xlDescending, DataOption1:=xlSortNormal
r.Sort Key2:=r2, Order2:=xlAscending, DataOption2:=xlSortNormal
Tri = r
End Function