K
Ken
I am using an Input box for my sheet to sort, I have 28 sorts and it is not
working. Can someone tell me if my code is incorrect. The sort works fine
when run from a Macro, but I am having problems with it using an input box.
Thank you
Ken
Sub All_Sorts1()
'
Dim MySort As Long
MySort = CLng(Application.InputBox(Prompt:="1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, or
28", Type:=1))
If MySort < 1 _
Or MySort > 28 Then
Exit Sub
End If
Range("C4").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.sort Key1:=Range("D4"), Order1:=xlAscending, Key2:=Range("G4") _
, Order2:=xlAscending, Key3:=Range("E4"), Order3:=xlAscending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Range("B1:B3").Select
MySort = CLng(Application.InputBox(Prompt:="1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, or
28", Type:=1))
If MySort < 1 _
Or MySort > 28 Then
Exit Sub
End If
Range("C4").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.sort Key1:=Range("D4"), Order1:=xlDescending,
Key2:=Range("G4") _
, Order2:=xlAscending, Key3:=Range("E4"), Order3:=xlDescending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Range("B1:B3").Select
MySort = CLng(Application.InputBox(Prompt:="1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, or
28", Type:=1))
If MySort < 1 _
Or MySort > 28 Then
Exit Sub
End If
Range("C4").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.sort Key1:=Range("K4"), Order1:=xlAscending, Key2:=Range("J4") _
, Order2:=xlAscending, Key3:=Range("I4"), Order3:=xlAscending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Range("B1:B3").Select
MySort = CLng(Application.InputBox(Prompt:="1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, or
28", Type:=1))
If MySort < 1 _
Or MySort > 28 Then
Exit Sub
End If
Range("C4").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.sort Key1:=Range("K4"), Order1:=xlAscending, Key2:=Range("J4") _
, Order2:=xlAscending, Key3:=Range("I4"), Order3:=xlDescending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Range("B1:B3").Select
End Sub
working. Can someone tell me if my code is incorrect. The sort works fine
when run from a Macro, but I am having problems with it using an input box.
Thank you
Ken
Sub All_Sorts1()
'
Dim MySort As Long
MySort = CLng(Application.InputBox(Prompt:="1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, or
28", Type:=1))
If MySort < 1 _
Or MySort > 28 Then
Exit Sub
End If
Range("C4").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.sort Key1:=Range("D4"), Order1:=xlAscending, Key2:=Range("G4") _
, Order2:=xlAscending, Key3:=Range("E4"), Order3:=xlAscending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Range("B1:B3").Select
MySort = CLng(Application.InputBox(Prompt:="1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, or
28", Type:=1))
If MySort < 1 _
Or MySort > 28 Then
Exit Sub
End If
Range("C4").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.sort Key1:=Range("D4"), Order1:=xlDescending,
Key2:=Range("G4") _
, Order2:=xlAscending, Key3:=Range("E4"), Order3:=xlDescending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Range("B1:B3").Select
MySort = CLng(Application.InputBox(Prompt:="1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, or
28", Type:=1))
If MySort < 1 _
Or MySort > 28 Then
Exit Sub
End If
Range("C4").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.sort Key1:=Range("K4"), Order1:=xlAscending, Key2:=Range("J4") _
, Order2:=xlAscending, Key3:=Range("I4"), Order3:=xlAscending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Range("B1:B3").Select
MySort = CLng(Application.InputBox(Prompt:="1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, or
28", Type:=1))
If MySort < 1 _
Or MySort > 28 Then
Exit Sub
End If
Range("C4").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.sort Key1:=Range("K4"), Order1:=xlAscending, Key2:=Range("J4") _
, Order2:=xlAscending, Key3:=Range("I4"), Order3:=xlDescending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Range("B1:B3").Select
End Sub