Hi, I currently have a code that automatically sorts data on multiple worksheets when the workbook is open and it works fine.
Most cells in the E9:J28 Range have no fill colour; however, there are some cells (in rows) that are intentionally blacked out.
Can anyone help me out to tweak this VBA code so that:
- Data still gets sorted the same.
- ONLY the text moves.
- All cells in the E9:J28 range keep their current formatting (the only format difference in the range is fill colour as mentioned).
Thanks in advance!
Most cells in the E9:J28 Range have no fill colour; however, there are some cells (in rows) that are intentionally blacked out.
Can anyone help me out to tweak this VBA code so that:
- Data still gets sorted the same.
- ONLY the text moves.
- All cells in the E9:J28 range keep their current formatting (the only format difference in the range is fill colour as mentioned).
Thanks in advance!
Code:
Private Sub Workbook_Open()
Dim ws As Worksheet
For Each ws In Worksheets
If ws.Name <> "Data" Then
'Top Left
ws.Sort.SortFields.Clear
ws.Sort.SortFields.Add Key:=Range("J9:J28"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ws.Sort.SortFields.Add Key:=Range("E9:E28"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ws.Sort
.SetRange Range("E9:J28")
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End If
Next ws
End Sub
Last edited: