I'm trying to custom sort a column on a single worksheet.
The first part of my macro sorts by column 'B' (text column) alphabetically, then by column 'C' (date) newest first. This works fine.
The second part that I'm struggling to get working is custom sorting column 'B' once more based on certain keywords which are in an array.
I'm new to using VBA and have searched high and low for what I'm sure is probably a very simple process.Option Explicit ' Sort column B alphabetically, then by column C by date with most recent first Sub SortData() Columns.Sort key1:=Columns("B"), Order1:=xlAscending, Key2:=Columns("C"), Order2:=xlDescending ' Custom list sort order using keywords ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add _ Key:=Range("B1", Range("B1").End(xlDown)), SortOn:=xlSortOnValues, Order:=xlAscending, _ CustomOrder:="Fire,Natural event,Flood", _ DataOption:=xlSortNormal End Sub
Can the sort on column 'B' just include a single word from a cell, or does it have to contain all the words in a cell (including case sensitive)?
Thanks!





Reply With Quote