I have some values that are pasted over from another macro, always starting at C6 and spanning from row 6-11, however the number of columns will change every time.
What I'd like to do is to sort the data table by row 11 values, left to right, from small to large. So the sort range will always be "C6:?11"
Here is what I have right now, mainly from a recorded macro with a few edits:
Dim active As Worksheet
Set active = ActiveSheet
Range("C6").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
active.Sort.SortFields.Clear
active.Sort.SortFields.Add2 Key:=Range( _
"C11:I11"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With active.Sort
.SetRange Range("C6:I11")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
I believe the problem lies with the "C11:I11" part, but I'm not sure what to change it to. The code also looks quite messy so if there's a better way to write this that'll be great.
I'm very new to VBA, any help would be appreciated!