我正在尝试根据 D 列中是否有任何文本将某一行的颜色更改为黄色。我已经为另一个单元格设置了 5 种不同的颜色,但是需要这个来覆盖那些颜色。如果我说“是”,我就可以让它工作,因为它是一个预先确定的值。但是,我需要输入各种文本和数字,这样就不会出现这种情况。
以下是我目前收集的内容,但需要将“是”更改为该单元格内的任何文本。
Private Sub Worksheet_Change(ByVal 目标作为范围)
Set MyPlage = Range("T8:T1000")
For Each Cell In MyPlage
Select Case Cell.Value
Case Is = "Cancelled"
Cell.EntireRow.Interior.ColorIndex = 8
Case Is = "Rejected"
Cell.EntireRow.Interior.ColorIndex = 3
Case Is = "Completed"
Cell.EntireRow.Interior.ColorIndex = 4
Case Is = "Pending"
Cell.EntireRow.Interior.ColorIndex = 15
Case Is = "Accepted"
Cell.EntireRow.Interior.ColorIndex = 39
Case Else
Cell.EntireRow.Interior.ColorIndex = xlNone
End Select
Next
Set MyPlage = Range("D8:D1000")
For Each Cell In MyPlage
Select Case Cell.Value
Case Is = "YES"
Cell.EntireRow.Interior.ColorIndex = 6
End Select
Next
子目录结束
谢谢詹姆斯
答案1
基本上你不想做一个选择案例只是检查单元格是否为空
子运行()
Set myplage = Range("D8:D1000")
For Each cell In myplage
If Not IsEmpty(cell.Value) Then
cell.EntireRow.Interior.ColorIndex = 6
End If
Next