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)


Purchase DateTransaction DescriptionAmountD/CAccount BalREFSICAUTHBAL IDPost Date
01/15/2008
ATHLETA ONLINE 0848700 877-328-4538 OH
$240.95CR ADDL 9106.37 M13FFHI11531OU1BUY 59690000009999806/18
06/16/2015CVS/PHARMACY #09914 00 AUBURN CA $4.07 9,106.37M12FFH05230XND0ODI 59126161359999806/18
04/02/2001
SUNRISE NATURAL FOODS AUBURN CA $30.74 9,106.37M05FFH7364980213FT 54996161949999806/18
06/18/2015DELTA AIR LINES ATLANTA USA $25.00 M04FFHM4228F4822CU 45115171159999806/19
02/15/2001
COSTCO WHSE #0670 0000 SPOKANE WA
$162.12 M13FFK24447YZEISEZ 53006191759999806/22
01/19/2008
WAL-MART SUPERCENTER 4 SPOKANE WA $18.31 M05FFJG05371XR0D6U 53102191509999806/22

<colgroup><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>


Any help with this is greatly appreciated, thanks!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
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,216,588
Messages
6,131,589
Members
449,657
Latest member
Timber5

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