leosandler
New Member
- Joined
- Oct 5, 2021
- Messages
- 1
- Platform
- MacOS
The VBA code I have below works for dynamically sorting the items in my Excel Table by date. I want to send all rows with the status marked as "DONE" to the bottom of my table automatically, while ensuring that the rows before are kept in order. The code I have below can dynamically sort dates, but only will send rows with the "DONE" status to the bottom of multiple rows containing the same date (which isn't the desired behaviour, since I want these items at the bottom of the table, not just the bottom of a specific date). Otherwise, the row order stays the same. Any suggestions?
Thanks
Thanks
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim tbl As ListObject, wRow As Long
Dim Deadlines As ListObject
Dim SortCol As Range
Set tbl = ActiveSheet.ListObjects("AllDeadlines")
Set SortCol = Range("AllDeadlines[Date]")
If Not Intersect(Target, SortCol) Is Nothing Then
With tbl.Sort
.SortFields.Clear
.SortFields.Add Key:=SortCol, Order:=xlAscending
.Header = xlYes
.Apply
End With
End If
If Target.CountLarge > 1 Then Exit Sub
If Not Intersect(Target, tbl.ListColumns("Status").Range) Is Nothing Then
If UCase(Target.Value) = "DONE" Then
Application.ScreenUpdating = False
wRow = Target.Row - tbl.HeaderRowRange.Row
tbl.ListRows.Add AlwaysInsert:=True
tbl.DataBodyRange.Rows(wRow).Copy tbl.DataBodyRange.Rows(tbl.ListRows.Count)
tbl.ListRows(wRow).Delete
End If
End If
End Sub