[英]If Cell Contains Value, Color Entire Row
I'm trying to color the entire row of any cell that contains "C" within a particular column. 我正在尝试为特定列中包含“ C”的任何单元格的整个行着色。 there also exist "P"'s that I do not want to color.
还有我不想着色的“ P”。 Here is my code.
这是我的代码。
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
I get an object error on the .Value = IIf(Interior.ColorIndex = 15, "C", "P")
我在
.Value = IIf(Interior.ColorIndex = 15, "C", "P")
上遇到对象错误
I am assuming that if the cell contains a "C" and doesn't contain a "P" then color it. 我假设,如果单元格包含“ C”而不包含“ P”,则为其上色。
Examples 例子
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.