I've been struggling with this issue in the past 3 days, so please help...
What I want to do is to when I run a macro1 (for the sake of the argument):
- Window would pop up to select a range of which cells should be sorted
- Have these sorted via last column selected (or the 5th) (lowest to highest numbers)
The issue here is that selected area would change eveytime (I create something like a tree in excel), so it cannot be a specific column that needs to be sorted by the last one (or the 5th in this case) of the selected (in the code below I do not know how to change I11:I15)
What I got and it does not work:
Sub RangeSelectionPrompt()
Dim rngStart As Range
Set rngStart = Application.InputBox("Select a range", "Obtain Range Object", Type:=8)
Set rngStart = Selection
rngStart.Select
ActiveWorkbook.Worksheets("CALCULATION").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("CALCULATION").Sort.SortFields.Add Key:=Range( _
"I11:I15"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("CALCULATION").Sort
.SetRange rngStart
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub