我正在尝试为特定列中包含“C”的任何单元格的整行着色。还存在“P”,我不想着色。这是我的代码。
<div class="row" style=" margin-top:0px;height:100px; ">
<div class="col col-25" style="background-color:#c8c8c8;text-align:center;padding:0px;">
<div>
<img src="img/task.png" style="display:block; margin:auto;margin-top:10px;">
<div style="margin-top:20px; margin-left:5px;"><label style="font-size:11px;">My Tasks</label></div>
</div>
</div>
<div class="col col-50" style="background-color:#413d3a;text-align:center;padding:0px; ">
<img src="img/document.png" style="display:block; margin:auto;margin-top:10px;">
<div style="margin-top:20px; margin-left:5px;"><label style="font-size:11px; color:#fff;">My Documents</label></div>
</div>
<div class="col col-25" style="background-color:#c8c8c8;text-align:center;padding:0px; ">
<img src="img/Newsfeed.png" style="display:block; margin:auto;margin-top:10px;">
<div style="margin-top:20px; margin-left:5px;"><label style="font-size:11px; ">Newsfeed</label></div>
</div>
</div>
我在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
答案 0 :(得分:2)
我假设如果单元格包含&#34; C&#34;并且不包含&#34; P&#34;然后给它着色。
实施例
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