Sort asscending

Damo10

Active Member
Joined
Dec 13, 2010
Messages
460
Hi,

I have several sheets where I would like to sort the data in rows 11 to the last used row in assending order, the data starts in cell B11 and the last column is DL but I would like the sort based on the name in column C.

Could someone show me how this would be done with VBA?

Regards
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I recorded a macro to do a custom sort based on a selected set of cells and it came back OK, see if you can adapt this to a range that you need.

Sub mcrSort()
'
' mcrSort Macro
'
'
Range("A11:A20").Select
ActiveWorkbook.Worksheets("Sheet4").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet4").Sort.SortFields.Add Key:=Range("A11:A20") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet4").Sort
.SetRange Range("A11:A20")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
 
Upvote 0
Or similarly,

Code:
Sub SortIt()
    Dim wks       As Worksheet
 
    Set wks = Worksheets("Sheet1")  ' change as required
 
    With wks.Sort
        .SortFields.Clear
        .SetRange Intersect(wks.UsedRange, _
                            wks.Range("A11", wks.Cells(wks.Rows.Count, wks.Columns.Count)))
        .SortFields.Add Key:=wks.Range("C11"), _
                        SortOn:=xlSortOnValues, _
                        Order:=xlAscending, _
                        DataOption:=xlSortNormal
        .Header = xlYes         ' or xlNo
        .MatchCase = False      ' or True
        .Orientation = xlTopToBottom
        .Apply
    End With
End Sub
 
Last edited:
Upvote 0
Hi SHG

I have just tried your code and am getting a runtime error 438 on line

Code:
.SetRange Intersect(.UsedRange, .Range("A11", Cells(.Rows.Count, .Columns.Count)))

Regards
 
Upvote 0
Grab the code again from my post.
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,909
Members
452,949
Latest member
beartooth91

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