Sorting VBA

charlesfowler72

New Member
Joined
Aug 9, 2012
Messages
37
Still fairly new at this, hopefully this will be simple enough for someone but I am having trouble setting the ranges. Below is the data.

DayTimeCoEvent
Wednesday0900UKX
Tuesday0800USX
N/AN/AEUX
Tuesday0900USX
TuesdayN/ACAX
Tuesday1200EUX
Tuesday0800EUX

<tbody>
</tbody>

So I am looking to sort with different layers, Firstly by day so Monday, Tuesday....N/A at the top. Then by Time 0900,1000,1100...N/A at the bottom.Then finally and most difficult by country with a customer list by US, EU, UK, CA.
I have tried recording by the range will be static but my table length varies day by day so it need to be A1:end. The final results would be as follows....

DayTimeCoEvent
N/AN/AEUX
Tuesday0800USX
Tuesday0800EUX
Tuesday0900USX
Tuesday1200EUX
TuesdayN/ACAX
Wednesday0900UKX

<tbody>
</tbody>

Any help would be incredible, thanks.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
try this and see whether it works

Code:
Sub test()
Dim r As Range
Set r = Range("A1").CurrentRegion
Set r = r.Offset(1, 0).Resize(r.Rows.Count - 1)
       
   
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=r.Columns("A:A"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
        "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", DataOption:= _
        xlSortNormal
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=r.Columns("B:B"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        MsgBox "macro done"
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

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