在我的表格中,日期格式为“dddd,mmmm dd,yyyy”。例如“2020 年 7 月 5 日,星期日”。我希望宏格式化包含“星期日”一词但无法正常工作的单元格。我可以将其更改为 dd 字符串(即 17)或 yyyy 字符串(即 2020)并且它可以工作,但不能使用包含文本的 dddd 或 mmmm 字符串。
Sub colour()
Dim rng As range
Dim lastRow As Long
Dim cell As range
lastRow = Cells(Rows.Count, 3).End(xlUp).Row
Set rng = range("J2:J" & lastRow)
For Each cell In rng
'If I change "Sunday" to "17" for example, or "2020", the routine works, but I cannot get it to find
'the dddd string
If InStr(cell.Value, "Sunday") > 0 Then
range(cell.Address).Interior.ColorIndex = 19
Else
range(cell.Address).Interior.ColorIndex = 0
End If
Next cell
End Sub