I'm trying to color the entire row of any cell that contains "C" within a particular column. there also exist "P"'s that I do not want to color. 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")
I am assuming that if the cell contains a "C" and doesn't contain a "P" then color it.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.