+ Reply to Thread
Results 1 to 8 of 8

Highlight rows that matches the wildcard string

Hybrid View

  1. #1
    Registered User
    Join Date
    07-08-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    53

    Highlight rows that matches the wildcard string

    Hi there, good day!

    I am not sure if conditional formatting can do this but I want to search for a text in my
    entire sheet (Log File) of 500 entries and state that;

    IF any cell in Column B has the string "Unknown", then highlight corresponding Row (yellow).

    Also, IF any cell in Column B has the string "ERROR", then bold (in red) the words in the cell.

    Any help will be appreciated. I've attached sample file in the 'Log File (My Requirements)' tab.
    Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Highlight rows that matches the wildcard string

    Try this ...
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    07-08-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Highlight rows that matches the wildcard string

    Thanks Bob!

    I hope you don't mind pasting the vba codes here 'cos i can't seem to view the codes in the spreadsheet that you attached. Many thanks!

  4. #4
    Registered User
    Join Date
    07-08-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Highlight rows that matches the wildcard string

    I read up that it is possible to use a conditional formatting instead of a macro to search for wildcard string and highlight the respective cells. However I would like to use a button that allows to automatically highlight after finding the strings "Unknown" and automatically change the color of the words in the cell red after it founds the string "Error". I will be most glad if anyone can teach me how to go about implementing it. Here are the codes that i have amended. Many thanks!

    Sub HiLite()
    With Range("B20:B500")
    .FormatConditions.Delete
    .FormatConditions.Add Type:=xlExpression, Formula1:= _
           "=$B1=""Unknown"""
    If Range("B20").Interior.ColorIndex = 3 Then
    .Interior.ColorIndex = xlNone
    Else
    .Interior.ColorIndex = 3
    End If
    End With
    End Sub

  5. #5
    Registered User
    Join Date
    07-08-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Highlight rows that matches the wildcard string

    Hi,

    I have managed to revise my code which allows the macro to search for the unique strings and highlights the cells. It works well but I encountered a problem when i added in this code to clear highlights.
    Option Explicit
    
    Sub CLEAR()
    ' CLEAR Macro
    
        Range("B1:B500").Select
        Selection.ClearHighlight
    End Sub
    When I run the macro, it will prompt me to this line.
    FindAndHighlight "ERROR", RiskRange, 3 'Red'
    Could anyone tell me what seem to be the problem here? I have attached a SAMPLE1 file for your reference.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    07-08-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Highlight rows that matches the wildcard string

    Hi all,

    I've decided to forgo the 'Remove highlights button' . However, for the benefit of those who are trying to find the macro that will find the unique string and higlight the cell, here it is:

    Sub FindAndHighlight(SearchData As Variant, SearchRange As Range, HighlightColor As Long)
    
       Dim FirstAddress As String
       Dim SearchCell As Range
       Dim SrcWks As Worksheet
    
         Set SrcWks = Worksheets(SearchRange.Parent.Name)
         Set SearchCell = SearchRange.Find(What:=SearchData, After:=SearchRange.Cells(1, 1), _
                            LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, _
                            SearchDirection:=xlNext, MatchCase:=False)
                            
         If Not SearchCell Is Nothing Then
            FirstAddress = SearchCell.Address
              Do
                  SearchCell.Cells.Interior.ColorIndex = HighlightColor
                  
                Set SearchCell = SearchRange.FindNext(SearchCell)
              Loop While Not SearchCell Is Nothing And SearchCell.Address <> FirstAddress
         End If
              
    End Sub
    
    Sub HighlightRisk()
      
       Dim LastRow As Long
       Dim RiskCol As Variant
       Dim RiskRange As Range
       Dim StartRow As Long
         
        RiskCol = "B"
         StartRow = 1
          With Worksheets("My Requirement")
            LastRow = .Cells(.Rows.Count, RiskCol).End(xlUp).Row
            LastRow = IIf(LastRow < StartRow, StartRow, LastRow)
            Set RiskRange = .Range(.Cells(StartRow, RiskCol), .Cells(LastRow, RiskCol))
          End With
          
          FindAndHighlight "Unknown", RiskRange, 6      'Yellow'
          FindAndHighlight "ERROR", RiskRange, 3    'Red'
          
    End Sub
    Hope it helps! Happy coding! =)

  7. #7
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Highlight rows that matches the wildcard string

    My solution was addng conditional formatting to the sheet.

  8. #8
    Registered User
    Join Date
    02-20-2016
    Location
    Hamburg, Germany
    MS-Off Ver
    Office for Mac 2011
    Posts
    1

    Re: Highlight rows that matches the wildcard string

    Thank you so much for the sample files! Been searching the internet for months for a solution to this.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1