VBA - Sort table by data ascending

MrTreasury

New Member
Joined
May 17, 2019
Messages
11
Hello forum,

I hope you're all well.

I'm in need of help as I've just not been able to figure this out. I'm looking to sort a table out through a macro.

The table's range is B2:F30, where B2 is the table's headers. Column F contains the dates I require sorting.

I did record a macro and attempt to adapt it and copy it into the main piece of code I'm writing but seem to get numerous errors whenever I tweak it.

I had initially tried:
Code:
ws.Range("B3:F30").Sort key1:=Range("F3"), Order1:=xlAscending, Header:=xlNo, DataOption1:=xlSortNormal

I use range B3:F30 purely as I just wanted the code to work on the area I wanted rather than the table itself hence the ranges and header being contrary to the start of my post.

Anyone have any tips/pointers or solutions?

Kind regards,

MrT
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
How about
Code:
ws.Range("B3:F30").Sort key1:=[COLOR=#ff0000]ws.[/COLOR]Range("F3"), Order1:=xlAscending, Header:=xlNo, DataOption1:=xlSortNormal
 
Upvote 0
The code is golden.

Protected sheet, merged cells, is variable ws assigned, are you looking at the right sheet?
 
Upvote 0
How about
Code:
ws.Range("B3:F30").Sort key1:=[COLOR=#ff0000]ws.[/COLOR]Range("F3"), Order1:=xlAscending, Header:=xlNo, DataOption1:=xlSortNormal

The code is golden.

Protected sheet, merged cells, is variable ws assigned, are you looking at the right sheet?


All fixed, the range was a table - once I converted to range, ran the code it all worked.

Thanks for your help guys
 
Upvote 0
Glad you sorted it & thanks for the feedback
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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