How to Delete Matching (1 Viewer)

AlaminK

New member
Local time
Today, 06:00
Joined
Apr 2, 2023
Messages
15
I wish to highlight cells in the search box. I want to delete partial matching. But I do not want to highlight if the search text is not a full match.
 
Last edited:

CarlettoFed

Member
Local time
Today, 02:00
Joined
Jun 10, 2020
Messages
119
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim bookName As String, authorName As String
Dim strStartColumn As String, strEndColumn As String
Dim intStartRow As Integer, intEndRow As Integer
Dim intRow As Integer
    bookName = Range("G2")
    authorName = Range("G3")
    strStartColumn = "B"
    strEndColumn = "D"
    intStartRow = 2
    intEndRow = 13
    Range(strStartColumn & intStartRow & ":" & strEndColumn & intEndRow).Interior.Color = RGB(255, 255, 255)
    For intRow = 2 To 13
        If bookName <> "" And authorName <> "" Then
            If InStr(Range("B" & intRow), bookName) > 0 And InStr(Range("C" & intRow), authorName) > 0 Then HighlightData strStartColumn, strEndColumn, intRow
        ElseIf bookName <> "" Then
            If InStr(Range("B" & intRow), bookName) > 0 Then HighlightData strStartColumn, strEndColumn, intRow
        ElseIf authorName <> "" Then
            If InStr(Range("C" & intRow), authorName) > 0 Then HighlightData strStartColumn, strEndColumn, intRow
        End If
    Next
End Sub

Private Sub HighlightData(strStartColumn As String, strEndColumn As String, intRow As Integer)
    Range(strStartColumn & intRow & ":" & strEndColumn & intRow).Interior.Color = RGB(180, 0, 50)
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:00
Joined
May 7, 2009
Messages
19,245
maybe, change it to this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim bookName As String
    Dim authorName As String
    Dim rowCount As Integer
    
    Range("B2: D13").Interior.Color = RGB(255, 255, 255)
    
    If Range("G2").Value <> "" Then
        
        bookName = UCase(" " & Trim$(Range("G2")) & " ")
        For rowCount = 2 To 13
            If InStr(" " & UCase(Range("B" & rowCount).Value) & " ", bookName) Then
                Range("B" & rowCount & ": D" & rowCount).Interior.Color = RGB(180, 0, 50)
            End If
        Next rowCount
    End If
    
    If Range("G3").Value <> "" Then
    
        authorName = UCase(" " & Trim$(Range("32")) & " ")
        For rowCount = 2 To 13
        
            If InStr(" " & UCase(Range("C" & rowCount).Value) & " ", authorName) Then
                Range("B" & rowCount & ": D" & rowCount).Interior.Color = RGB(180, 0, 50)
            End If
        Next rowCount
    End If

End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:00
Joined
May 7, 2009
Messages
19,245
unfortunately i tried CarlettoFed, and still it is doing "partial" search.
 

Users who are viewing this thread

Top Bottom