VBA custom sort to last row

Mcstefan

New Member
Joined
May 17, 2014
Messages
48
Hi,

I have this code that sorts my data - sortData based on column A - sortDistribGr

lastrow = Cells(Rows.Count, 2).End(xlUp).Row
sortData = "A6:AF"
sortDistribGr = "A6:A"
Range(sortData & lastrow).Sort key1:=Range(sortDistribGr & lastrow), order1:=xlDescending, Header:=xlNo

I would like to do a custom sort instead and the order would be column A - sortData = "A6:AF", column H - sortBr = "H6:H"
and then column N - sortSupervisor = "N6:N"

How do I adapt the code above?
Thanks
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi,

You can sort a maximum of three columns using that syntax. If you need more it gets a bit more complicated.

I would shorten things a bit, though:
Code:
Sub mySort()
    Dim r   As Range
    Set r = Range(Cells(Rows.Count, "A").End(xlUp), "AF6") '.Resize(, Cells(, "AF").Column)
    r.Sort _
        key1:=Range("A:A"), order1:=xlDescending, _
        key2:=Range("H:H"), order2:=xlDescending, _
        key3:=Range("N:N"), order3:=xlDescending, _
        Header:=xlNo
End Sub


Regards,
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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