Multifaceted Sorting

mharper90

Board Regular
Joined
May 28, 2013
Messages
117
Office Version
  1. 365
Platform
  1. MacOS
I've added my code below, although I'm nowhere close to my desired task.

I'm trying to sort ws1 in a way that Column A (which contains either YES, NO, MDR, or DPL) will be in order of all of the YES & MDR together, followed by all of the NO, with DPL sifted throughout as required. From here, the YES and MDR should be in alphabetical order by name in column B. And the NO should be in alphabetical order by name after the YES and MDR group. To confuse it even more, there are some duplicate names with DPL in Column A. These should be fit in with the matching name, with no care for whether the matching name is YES, NO, or MDR. Lastly, for any name with DPLs attached to it, Column E should be used to sort them in chronological order, oldest date on top. I know this is quite confusing to read. Here's an example that I hope explains it better. btw, the data set starts in Row 7.

ABE
YESCole, Mike2 Feb 2019
DPLCole, Mike16 Feb 2019
MDRHotel, Jim4 Feb 2019
DPLHotel, Jim9 Feb 2019
YESJones, Sam2 Feb 2019
YESLupo, Mike2 Feb 2019
MDRPatches, Tim2 Feb 2019
YESSmith, John2 Feb 2019
DPLSmith, John10 Feb 2019
DPLSmith, John28 Feb 2019
NOAdams, Matt2 Feb 2019
NOBaker, Kyle2 Feb 2019
DPLBaker, Kyle19 Feb 2019
DPLBaker, Kyle22 Feb 2019
NOPhelps, Tom4 Feb 2019
NORoman, Tyler2 Feb 2019

<tbody>
</tbody>


Code:
Sub sortCol()

Dim ws1     As Worksheet: Set ws1 = ThisWorkbook.Sheets("Main Data")
Dim vSortList     As Variant
Dim LrC     As Long
Dim x     As Integer

ws1.Sort.SortFields.Clear

LrC = ws1.Range("A" & Rows.Count).End(xlUp).Row
vSortList = Array("YES", "MDR", "NO", "DPL")

On Error Resume Next

Application.AddCustomList ListArray:=vSortList
ws1.Range("A7:Y" & LrC).Sort Key1:=[E7], Order1:=xlAscending     'Date
ws1.Range("A7:Y" & LrC).Sort Key1:=[A7], ordercustos:=Application.CustomListCount + 1
ws1.Range("A7:Y" & LrC).Sort Key1:=[B7], Order1:=xlAscending     'Name

x = Application.GetCustomListNum(ListArray:=vSortList)
Application.DeleteCustomList x

ws1.Sort.SortFields.Clear

End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Giving this a bump since I'm in a weird time zone. The best answers always show up after I go to bed!
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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