下記のようなマクロを作成したのですが、ステータスを"Done"に変更した場合にセルの塗りつぶし及び文字の太字を無くしたいのにマクロが効きません。何がいけないのでしょうか?
Sub UpdateStatusToOverdue()
Dim rng As Range
Dim cell As Range
Dim ws As Worksheet
Dim statusList As String
' Define the status list (replace with your actual list if different)
statusList = "Done,In progress,On hold,Not Started,Overdue"
Set ws = Sheets("ToDoList")
' Define the range to check
Set rng = ws.Range("G5:G100")
' Remove data validation from H5:H100
ws.Range("H5:H100").Validation.Delete
' Check each cell in the range
For Each cell In rng
' If the cell value is negative and the status is not already "Overdue"
If cell.Value < 0 And cell.Offset(0, 1).Value <> "Overdue" Then
' Set the status to "Overdue"
cell.Offset(0, 1).Value = "Overdue"
' Color corresponding C and H cells in light red
cell.Offset(0, -4).Interior.Color = RGB(255, 153, 153) ' adjust the RGB values as needed
cell.Offset(0, 1).Interior.Color = RGB(255, 153, 153) ' adjust the RGB values as needed
' Change the font of G column cell to bold red
cell.Font.Bold = True
cell.Font.Color = RGB(255, 0, 0) ' adjust the RGB values as needed
ElseIf cell.Offset(0, 1).Value = "Done" And cell.Offset(0, -4).Interior.Color <> RGB(255, 255, 255) Then
' If the status is "Done" and the cell is not already in default format
cell.Offset(0, -4).Interior.ColorIndex = xlNone
cell.Offset(0, 1).Interior.ColorIndex = xlNone
cell.Font.Bold = False
cell.Font.Color = RGB(0, 0, 0) ' reset to black
End If
Next cell
' Restore data validation in H5:H100
With ws.Range("H5:H100").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=statusList
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
End With
End Sub