xlLeftToRight sort not reordering column headers during sort.
Hello. Been struggling with an issue for days now. I have a range of data that needs to be re-ordered from left to right descending and although I have the values in the range sorting, the corresponding headers are not sorting.
An example would be:
COL A B C
Row1 Abe Ben Cat
Row2 1 2 3
Row3 1 2 3
Row4 1 2 3
Row5-sum 3 6 9
And my sort is like this:
Range("A1:C5").Select
ActiveWorkbook.Worksheets("(2) Data").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("(2) Data").Sort.SortFields.Add Key:=Range( _
("A1:C5"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= xlSortNormal
With ActiveWorkbook.Worksheets("(2) Data").Sort
.SetRange Range("A1:C5")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
I have tried xlGuess, xlYes, and xlNo and each time the result is the same; my data is sorted correctly, but the columns are not. An example after sort would be:
COL A B C
Row1 Ben Abe Cat
Row2 3 2 1
Row3 3 2 1
Row4 3 2 1
Row5-sum 9 6 3
I can provide real data and real code, just thought this simple example would work, just let me know if I should post real data and code (no confidential info in data).
Thanks very much,
Dan
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago