Auto Sorting

MarieB

New Member
Joined
Jun 23, 2011
Messages
6
I would like to be able to enter data into a worksheet and have the data auto sort as it is entered. I have tried using macros (not real familiar with) and could not get it to successfully update. Here is an example of my worksheet.

<table border="0" cellpadding="0" cellspacing="0" width="652"><col width="103"><col width="180"><col width="70"><col width="87"><col width="212"><tr height="20"> <td class="xl72" style="height: 15pt; width: 77pt;" height="20" width="103">Ticket #</td> <td class="xl70" style="width: 135pt;" width="180">Agent
</td> <td class="xl65" style="width: 53pt;" width="70">Reviewer</td> <td class="xl64" style="width: 65pt;" width="87">Date</td> <td class="xl66" style="width: 159pt;" width="212">Comment
</td> </tr></table>

I would like column A (Ticket #) to be the primary sort and up date as data is entered.

Thank you for your help
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Me.UsedRange.Sort Key1:=Range("A2"), Order1:=xlAscending, _
        Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Application.EnableEvents = True
End Sub
 
Upvote 0
I used the developer tab and added this to the view code. Is there something I need to do activate the code once I add it? I entered a new line of data and it did not sort. I apologize, this is pretty foreign territory.
 
Upvote 0
Check on the Developer tab that macros are enabled (the lowest security setting).
 
Upvote 0
Should it auto sort after entering to the next row or do I need to do an additional step for this to happen. Thank you so much for your patience.
 
Upvote 0
It will auto sort when anything on the sheet is changed. That might be an issue and maybe you want it to sort when one particular column value is changed.


Also it will crash if you paste to multiple cells. That can be handled like this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
Me.UsedRange.Sort Key1:=Range("A2"), Order1:=xlAscending, _
        Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,795
Members
452,943
Latest member
Newbie4296

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