sort

JOEE1979

Active Member
Joined
Dec 18, 2022
Messages
250
Office Version
  1. 365
Platform
  1. Windows
I know how to sort a single column

VBA Code:
Range("A1:A11").Sort Key1:=Range("A1"), 
                       Order1:=xlAscending,
                       Header:=xlYes

But how would I sort columns "A" through "Z" and all columns 1 at a time (not connected to each other)?
 

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).
One way....
VBA Code:
Sub JOEE1979()
    Dim i As Integer
    For i = 1 To 26
        With Range(Cells(1, i), Cells(11, i))
            .Sort Key1:=.Cells(1, 1), Order1:=xlAscending, Header:=xlYes
        End With
    Next
End Sub
 
Upvote 0
Solution
I modified the vba just a bit to make it different cells

VBA Code:
Sub Sort_planner()
    Dim i As Integer
    For i = 3 To 38
        With Range(Cells(8, i), Cells(200, i))
            .Sort Key1:=.Cells(3, 8), Order1:=xlAscending, Header:=xlNo
        End With
    Next
End Sub

but its not working, and
.Sort Key1:=.Cells(3, 8), Order1:=xlAscending, Header:=xlNo
becomes highlighted
 
Upvote 0
.Cells(3, 8) should still be .Cells(1, 1).... it is the first cell in the range
 
Upvote 0
The "One way" answer provided by @MARK858 is the generic answer for the generic question. Therefore, the marked solution has been switched accordingly.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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