Mr Retirement
New Member
- Joined
- Nov 12, 2016
- Messages
- 46
Hi All,
I am working through this code to sort my data by color ... then delete the rows of that color.
The below code works to sort but my table starts in row 5 and the code overrides it and starts the sort in row 2.
Can anyone help adjust this code or have a better way to approach this?
Thanks,
Mr R
I am working through this code to sort my data by color ... then delete the rows of that color.
The below code works to sort but my table starts in row 5 and the code overrides it and starts the sort in row 2.
Can anyone help adjust this code or have a better way to approach this?
Code:
Dim wks As Worksheet
Set wks = Worksheets("Input")
With wks.Sort
With .SortFields
.Clear
.Add(wks.Range("B5"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(0, 0, 255)
.Add Key:=wks.Range("A5"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
End With
.SetRange wks.Range("B5", Range("B" & Rows.Count).End(xlUp)).CurrentRegion
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Thanks,
Mr R