Hi again everyone,
I am having an issue whereby an inputbox appears twice to direct my macro to sort columns.
What I am trying to do is ask the user for an single variable input corresponding to the column they wish to sort, ie. they select '1' then column one will sort, choosing '2' column to will sort, etc.
Sub macro3()
Dim a, b, c, d, e As Single
a = 1
b = 2
c = 3
d = 4
e = 5
Selection.CurrentRegion.Select
If InputBox("set me", "title") = a Then
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("B2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("B1:B12")
.Header = xlYes
.MatchCase = True
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ElseIf InputBox("set me") = b Then
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("c2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("c1:c12")
.Header = xlYes
.MatchCase = True
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Else
MsgBox "cya"
End If
End Sub
Do I need to set the inputbox as a variable?
Any help is very appreciated! Thanks for your time.
Bookmarks