I'm making a database for excel. The goal is to have the data input into it Auto sort by color and then Alphabetically.
I'm using the following VBA to auto sort.
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Not Intersect(Target, Range("A:A")) Is Nothing Then
Range("A1").Sort Key1:=Range("A2"), _
Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
End If
End Sub
And I've set up Macros for the color sorting as follows:
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
ActiveWorkbook.Worksheets("Master").ListObjects("Table2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Master").ListObjects("Table2").Sort.SortFields.Add( _
Range("Table2[Name]"), xlSortOnCellColor, xlDescending, , xlSortNormal). _
SortOnValue.Color = RGB(255, 0, 0)
With ActiveWorkbook.Worksheets("Master").ListObjects("Table2").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
The problem is once I input new data, the alphabetical sort overrides the color sort.
Can someone please help me make it so that the color sorting overrides the alphabetical?
Any help is greatly appreciated!
Bookmarks