Need to sort entire row by column A (ascending)

adibakale

Board Regular
Joined
Apr 10, 2015
Messages
52
I have a locked spreadsheet that I don't want users to be able to freely modify. I would like to add a Macro Button that when clicked, will sort the data.

The data is in Columns (A) to (L) and varies in row length - anywhere from 1 row to 1000. I would like to sort columns regardless of how many rows there are.

Column A stores dates, and I would like to sort all rows beginning in cell A4 since this is where the data starts.

Here is what my excel sheet looks like: (it usually contains anywhere from 1 - 1000 rows of data)


[TABLE="width: 1558"]
<colgroup><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD]Purchase Date[/TD]
[TD]Transaction Description[/TD]
[TD]Amount[/TD]
[TD]D/C[/TD]
[TD]Account Bal[/TD]
[TD]REF[/TD]
[TD]SIC[/TD]
[TD]AUTH[/TD]
[TD]BAL ID[/TD]
[TD]Post Date[/TD]
[/TR]
[TR]
[TD]01/15/2008
[/TD]
[TD]ATHLETA ONLINE 0848700 877-328-4538 OH
[/TD]
[TD]$240.95[/TD]
[TD]CR ADDL [/TD]
[TD] 9106.37 [/TD]
[TD]M13FFHI11531OU1BUY [/TD]
[TD]5969[/TD]
[TD]000000[/TD]
[TD]99998[/TD]
[TD]06/18[/TD]
[/TR]
[TR]
[TD]06/16/2015[/TD]
[TD]CVS/PHARMACY #09914 00 AUBURN CA [/TD]
[TD]$4.07[/TD]
[TD] [/TD]
[TD]9,106.37[/TD]
[TD]M12FFH05230XND0ODI [/TD]
[TD]5912[/TD]
[TD]616135[/TD]
[TD]99998[/TD]
[TD]06/18[/TD]
[/TR]
[TR]
[TD]04/02/2001
[/TD]
[TD]SUNRISE NATURAL FOODS AUBURN CA [/TD]
[TD]$30.74[/TD]
[TD] [/TD]
[TD]9,106.37[/TD]
[TD]M05FFH7364980213FT [/TD]
[TD]5499[/TD]
[TD]616194[/TD]
[TD]99998[/TD]
[TD]06/18[/TD]
[/TR]
[TR]
[TD]06/18/2015[/TD]
[TD]DELTA AIR LINES ATLANTA USA [/TD]
[TD]$25.00[/TD]
[TD] [/TD]
[TD][/TD]
[TD]M04FFHM4228F4822CU [/TD]
[TD]4511[/TD]
[TD]517115[/TD]
[TD]99998[/TD]
[TD]06/19[/TD]
[/TR]
[TR]
[TD]02/15/2001
[/TD]
[TD]COSTCO WHSE #0670 0000 SPOKANE WA
[/TD]
[TD]$162.12[/TD]
[TD] [/TD]
[TD][/TD]
[TD]M13FFK24447YZEISEZ [/TD]
[TD]5300[/TD]
[TD]619175[/TD]
[TD]99998[/TD]
[TD]06/22[/TD]
[/TR]
[TR]
[TD]01/19/2008
[/TD]
[TD]WAL-MART SUPERCENTER 4 SPOKANE WA [/TD]
[TD]$18.31[/TD]
[TD] [/TD]
[TD][/TD]
[TD]M05FFJG05371XR0D6U [/TD]
[TD]5310[/TD]
[TD]219150[/TD]
[TD]99998[/TD]
[TD]06/22[/TD]
[/TR]
</tbody>[/TABLE]


Any help with this is greatly appreciated, thanks!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Code:
Sub SortSheet()
    ActiveSheet.Unprotect
    ' Or if password protected:
    ' ActiveSheet.Unprotect Password:="YourPassword"
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("A4", Range("A64000").End(xlUp)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.ActiveSheet.Sort
        .SetRange Range("A4", Range("L64000").End(xlUp))
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    ActiveSheet.Protect
    
End Sub

Do you need help on adding the button too?
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

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