Hello,
The code below does not reference the answer from the input box. I am unsure how to make the sort "Custom order" to reference the answer given in the input box.
Any help would be appreciated.
Thanks!
Sub A_Test()
Answer = Application.InputBox("Please enter sort criteria", "Sort")
Range("A1").Select
'This is the section that does not correctly reference the answer from the input box.
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range("A2:XFD2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
Answer, DataOption:=xlSortNormal
With ActiveSheet.Sort
.SetRange ActiveSheet.UsedRange
.Header = xlYes
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
'Everything below has no issues working.
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range("A4:XFD4") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveSheet.Sort
.SetRange ActiveSheet.UsedRange
.Header = xlYes
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
Cells.Find(What:="#", after:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Columns("A:A").EntireColumn.Select
Selection.Cut
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Range("A2").FormulaR1C1 = "Time"
Range("A3").FormulaR1C1 = "sec"
Range("A4").ClearContents
Rows("4:4").Select
Selection.Copy
Rows("5:5").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
End Sub
Bookmarks