SAS or VBA excel sort data from left to right respecting column headers

0

I am trying to sort data as descending by row but to respect the names of the columns to show first the column with the highest value in the first month, and so on with all the lines of the month. I know that the first one prevails. It is what is done manually choosing the option to sort from left to right and sorting by rows in excel.

This code (which is not mine) does it but totally ignores the columns, it only listens to the lines and mixes the data of all the columns. Can someone help me please? Thanks in advance.

I would prefer in vba excel, but if someone knows how to do it in sas, it also works for me. Thanks

Sub Macro1()
'
' Macro1 Macro
' Keyboard Shortcut: Ctrl+Shift+S
'
    Range("d2:g2").Select
    Selection.Sort Key1:=Range("d2"), Order1:=xlAscending, Header:=c1 _
        , OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
        DataOption1:=xlSortNormal
    Range("d3:g3").Select
    Selection.Sort Key1:=Range("d3"), Order1:=xlAscending, Header:=c1 _
        , OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
        DataOption1:=xlSortNormal
        Range("d4:g4").Select
    Selection.Sort Key1:=Range("d4"), Order1:=xlAscending, Header:=c1 _
        , OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
        DataOption1:=xlSortNormal
End Sub

    
asked by vanmon 15.06.2017 в 15:39
source

1 answer

0

The macro you are using seems to have been generated automatically, this is because the ranges you use do not correspond to the ones in the table where Range ("d2: g2"). Select, replace it with A2: K13 or for the rank you want to order.

That is, Range ("d2: g2"). Select by Range ("A2: K13"). Select either touch a new macro or encode one correctly by hand.

    
answered by 23.10.2017 в 19:56