How to sort 3 paired columns from left to right?

SonnyTito

New Member
Joined
Sep 23, 2015
Messages
9
Looking for VBA code to sort 3 paired columns ascending fromleft to right based on a total at the bottom ?
I have 6 columns, paired by 2 next to each other from A to F.
This means the A and B, C and D, E and F need to stay adjacent to each other.
At the bottom of the B, D and F column the totals (sum) are calculated of thevalues in these columns.
How can I sort these columns based on the totals in ascending order from leftto right and that the paired columns AB, CD and EF remain paired and in thesame order.

Eg. AB-CD-EF becomes EF-AB-CD after sorting
Thank you for your input and help

 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I recorded a macro to sort each of the paired tables in as much time as it took me to do the actual sort. You can do the same. I would get rid of the rows that SELECT ranges. But other than that, you are mostly redy to go.

Jeff

Code:
Sub Macro9()
'
' Macro9 Macro
'


'
    ActiveWorkbook.Worksheets("Sheet7").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet7").Sort.SortFields.Add Key:=Range("A2:A4"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet7").Sort
        .SetRange Range("A1:B4")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("C1:D4").Select
    ActiveWorkbook.Worksheets("Sheet7").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet7").Sort.SortFields.Add Key:=Range("C2:C4"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet7").Sort
        .SetRange Range("C1:D4")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("E1:F4").Select
    ActiveWorkbook.Worksheets("Sheet7").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet7").Sort.SortFields.Add Key:=Range("E2:E4"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet7").Sort
        .SetRange Range("E1:F4")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub
 
Upvote 0
Thank you for your suggestions Jeffrey but is I look at the code, it seems to me the paired columns will be sorted row wise and that is not what I want.
The rows need to stay in the same order but the columns need to be sorted from left tonright.
 
Upvote 0

Forum statistics

Threads
1,216,111
Messages
6,128,899
Members
449,477
Latest member
panjongshing

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top