Mackeral
Board Regular
- Joined
- Mar 7, 2015
- Messages
- 249
- Office Version
- 365
- Platform
- Windows
The code below generates what I think are the proper keys and sort code but doesn't work.
Any idea why?
See the next post for more example.
And thanks for the help.
Mac
Any idea why?
Code:
Sub Data_Sort(SEET, Row_Rng, Col1, _
Optional Col2 = "", _
Optional Col3 = "", _
Optional Col4 = "", _
Optional Header_Xtrl As XlYesNoGuess = xlNo)
' Sort Data in a Sheet.
' If Col Number is Negative, sort it descending.
' Note: Subroutine assumes that "Rng_Row" _
begins with the Label row.
Prog = "Data_Sort"
' Check Row Range
Ptr = InStr(Row_Rng, ":")
If Ptr Then
Row1 = Left(Row_Rng, Ptr - 1)
Row2 = Mid(Row_Rng, Ptr + 1)
Else
Msg = """Row_Rng"" is not a valid Row Range."
Call Msg_Err(Prog, Msg, Row_Rng)
End If
SHEET.Sort.SortFields.Clear
Call Data_Sort_Arg(SHEET, 1, Row1, Row2, Col1)
Call Data_Sort_Arg(SHEET, 2, Row1, Row2, Col2)
Call Data_Sort_Arg(SHEET, 3, Row1, Row2, Co13)
Call Data_Sort_Arg(SHEET, 4, Row1, Row2, Col4)
With SHEET.Sort
.SetRange Range(Row_Rng)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub ' Data_Sort()
' ==========================================================
Sub Data_Sort_Arg(SHEET As Worksheet, Arg_Nr, Row1, Row2, Column)
' Sorting changed.
' 5/18/18 Created. WML
' 9/14/18 Changed "Add" to A"Add2".WML
' 9/14/18 Reworked for new System Sort code. WML
Prog = "Data_Sort_Arg"
Sheeet_Name = SHEET.Name
' Check Columns
If Column = "" Then
Exit Sub
ElseIf Not IsNumeric(Column) Then
Msg1 = "Column Pointer for Argument """ & Arg_Nr & """ is not a number."
Call Msg_Err(Prog, Msg1)
ElseIf Column > 0 Then
Sort_How = xlAscending
ElseIf Column < 0 Then
Column = -Column
Sort_How = xlDescending
Else ' Column = 0
Msg1 = "Column Pointer for Argument 'Col'" & Ptr & " is '0'."
Call Msg_Err(Prog, Msg1)
End If
Col = Col_Ptr(Column)
Sort_Rng = Col & (Row1 + 1) & ":" & Col & Row2
SHEET.Sort.SortFields.Add2 _
Key:=Range(Sort_Rng), _
SortOn:=(xlYes), _
Order:=Sort_How, _
DataOption:=(xlSortNormal)
End Sub ' Data_Sort_Arg
See the next post for more example.
And thanks for the help.
Mac