Private Sub cmdSort_Click()
Dim r As Range
Dim s As Range
Dim sign As Range
Dim lastrow As Integer
Dim catcount As Double
Dim catcount2 As Double
lastrow = Range("E3").End(xlDown).Row
catcount = lastrow
Set r = Range("G3")
Set s = Range("H3")
Set sign = Range("A3")
Set subsign = Range("B3")
While r.Row <= lastrow
If sign.Value <> "" Then
s.Formula = catcount + 0.1
r.Formula = r.Offset(0, -2).text
catcount2 = catcount
catcount = catcount - 1
Else 'populate cell with value in cell above
r.Formula = r.Offset(-1, 0).text
s.Formula = catcount2
End If
'drop down one row
Set s = s.Offset(1, 0)
Set r = r.Offset(1, 0)
Set sign = sign.Offset(1, 0)
Wend
Call FourKeySort
End Sub
Sub FourKeySort()
SortAll "H3"
SortAll "G3"
SortAll "J3"
SortAll "I3"
SortAll "E3"
End Sub
Sub SortAll(x As String)
Range(x).Sort _
Key1:=Range(x), _
Order1:=xlDescending, _
Header:=xlNo
End Sub
testsort.xlsx
ASKER
ASKER
ASKER
ASKER
ASKER
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
TRUSTED BY