简体   繁体   中英

Highlight all cells that contain a value in another cell

I am using Excel

I would like to hihglight every cell in a spreadsheet that contains (Case-Insensitive) the value entered in another cell.

I have been playing around with conditional formating but I have not found success.

This small macro uses the value found in cell A1 and hi-lights any cell containing that value:

Sub ColorCells()
    Dim s As String, r As Range
    s = Range("A1").Text
    For Each r In ActiveSheet.UsedRange
        If InStr(1, r.Text, s) > 0 Then
            r.Interior.ColorIndex = 27
        End If
    Next r
End Sub

For example:

在此处输入图片说明

Excel treats a 0 ( zero ) as FALSE. By strict definition, anything that is not FALSE is TRUE. Conditional formatting rules based upon a formula are only looking for a TRUE or FALSE; anything more than that is superfluous. The formula you described in the comments section of your original question could be pared down to,

=COUNTIF(A4,"*" & $A$2 & "*")

Another method for case insensitive search is to see if SEARCH returns a position (eg it was found) or an error (eg it was not found).

=ISNUMBER(SEARCH($A$2, A4))

This can optionally be turned into a case-sensitive search by swapping out SEARCH for FIND .

=ISNUMBER(FIND($A$2, A4))

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.

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