[英]If Cell Contains Value, Color Entire Row
我正在嘗試為特定列中包含“ C”的任何單元格的整個行着色。 還有我不想着色的“ P”。 這是我的代碼。
Sub color()
Dim lastRow As Long
With Sheets("MP Parameters")
lastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
With .Range("K5:K" & lastRow)
.Value = IIf(Interior.ColorIndex = 15, "C", "P")
End With
End With
End Sub
我在.Value = IIf(Interior.ColorIndex = 15, "C", "P")
上遇到對象錯誤
我假設,如果單元格包含“ C”而不包含“ P”,則為其上色。
例子
Sub color()
Dim lastRow As Long
Dim x As Long
With Sheets("MP Parameters")
lastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
For x = 5 To lastRow
If .Cells(x, "K") Like "*C*" And Not .Cells(x, "K") Like "*P*" Then
.Rows(x).Interior.ColorIndex = 15
End If
Next
End With
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.