繁体   English   中英

如果单元格包含特定值,则以红色突出显示行到特定列

[英]Highlight Row in Red up to certain column if cell contains certain value

如果 J 列中的单元格值包含值 427,我有一个小宏以红色突出显示整行。见下文...

Dim lr As Long
lr = Worksheets("owssvr").Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row

         Dim cell As Range  
            For Each cell In Range("J2:J" & lr)
               If cell.Value = 427 Then
               cell.EntireRow.Interior.Color = 255     
    End If

我想做的是修改宏,使其仅以红色突出显示包含数据的行的部分,而不是整行(在此表的情况下,直到列 AF)。 谢谢你。

如果您只想突出显示列AF之间的行,请尝试-

Sub Highlight()
Dim lr As Long
lr = Worksheets("owssvr").Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row

    Dim cel As Range
    For Each cel In Range("J2:J" & lr)
        If cel.Value = 427 Then
           Range("A" & lr & ":F" & lr).Interior.Color = 255
        End If
    Next
    
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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