Table auto sort

nparsons75

Well-known Member
Joined
Sep 23, 2013
Messages
1,256
Office Version
  1. 2016
I have a table that consists of approximately 8 rows. Each row has data in order of priority. example, priority 1 at the top, 8 at the bottom. The priorities do change. For example, what is priority 3 may become priority 1.

I need to be able to quickly change the priority. Ideally by changing the priority number all the rows will reorganise automatically.

Currently I have to cut, copy and paste which becomes messy.

Also to bear in mind the spreadsheet is shared and used by many people.

Hopefully, someone can assist which will be greatly appreciated, thank you.
 
just an issue i have come across. If i delete the top row as we do not need it anymore that leaves a blank row, the module will obviously no longer work. is there a workaround for this do you know of?


Replace the code I posted earlier with the following code. This way, it doesn't matter whether or not you keep the row of headers. It will always sort column A in ascending order.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim SRng As Range
    Set SRng = Me.Range("A1").CurrentRegion    

    If Not Intersect(SRng, Target) Is Nothing Then
        
        SRng.Sort _
            Key1:=Me.Range("A1"), _
            Order1:=xlAscending, _
            Header:=xlGuess
    End If
    
End Sub
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,226,217
Messages
6,189,688
Members
453,563
Latest member
Aswathimsanil

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