Auto Sort rows based on a selection from a drop down menu

mscholnick

New Member
Joined
Apr 9, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I've created a rows that color code the line with conditional formatting based on the 5 choices in the drop down menu in the "Status" column. I did a custom sort and built a list to put the rows in the desired sequence. Now I want that sort feature to happen automatically based on the Status selected on the drop down. Possible?


1712686772155.png
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Welcome to the Board!

Auto sorting would require the use of VBA. To get the VBA code needed in order to sort your range, you can turn on your Macro Recorder, and record yourself sorting the range manually. Then stop the Macro Recorder, and view the VBA code you just recorded. This will give you a good start on the code the need.

We will then want to drop that VBA code in a "Worksheet_Change" event procedure, which is VBA code that is automatically run whenever a cell is manually updated. In your screen print above, if "Status" is in column G, we will want to watch for changes to column G.

To put this VBA code in the proper place (it MUST be in the sheet module in VBA), simply go to the sheet where your data exists, right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this VBA code shell in the VB Editor window that pops up:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    'Exit code if update made is not in column G
    If Intersect(Target, Columns("G:G")) Is Nothing Then Exit Sub
   
    'Put your sorting code below here
   

End Sub
You can see where you would drop the recorded sorting part of your VBA code.

If you need help getting all of this to work, please copy/paste the recorded sorting VBA code I instructed you on how to get above, and let us know exactly which column the "Status" column is located in, if it is not in column G.
 
Upvote 0
Thank you! I will give it a try and let you know if I need help with the recorded VBA code.
 
Upvote 0
I recorded a script for the sort. However, when I run the script, it does not take into account the custom list I created. Below are the script and the custom list. It should sort based on the Status (select using drop down menu) column in the order (PO Received, Hot Prospect, Qualified Prospect Interested Prospect, Prior Hot Prospect. Rather, it sorted as shown below.

I tried recording while building the custom list under custom sort, but got the same result.

Any help greatly appreciated

1712758009123.png


1712758217205.png
 
Upvote 0
I do not know anything about the Office Scripts, I only use VBA.
So what I was suggesting is to turn on your VBA Macro Recorder, and record yourself performing the sort steps manually, and then stopping the recorder and viewing the recorded code.
 
Upvote 1

Forum statistics

Threads
1,215,214
Messages
6,123,664
Members
449,114
Latest member
aides

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