[英]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.