简体   繁体   English

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

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

I have a small macro that highlights an entire row in red if the cell value in J column contains the value 427.See below...如果 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

What I would like to do is to amend the macro so that it only highlights in red the section of the row that contains data, rather than the entire row (in this tables case, up to column AF).我想做的是修改宏,使其仅以红色突出显示包含数据的行的部分,而不是整行(在此表的情况下,直到列 AF)。 Thank you.谢谢你。

If you only want to highlight row between columns A & F then try-如果您只想突出显示列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