繁体   English   中英

如果单元格包含值,则整行显示颜色

[英]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”,则为其上色。

例子

  • “ ABCDEF”:为其着色
  • “ ABCP”:请勿着色
  • “ ABC”:为其着色
  • “ DEFGH”:请勿着色

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM