Forum Discussion

Tez_Clews's avatar
Tez_Clews
Copper Contributor
Feb 16, 2021
Solved

Formula to find specific random text in a cell

Hi,   I am somewhat of a novice in Excel but I'm working on a project for work. I am trying to use a formula to conditional format a row when text is found in a cell, however the text although wil...
  • HansVogelaar's avatar
    Feb 16, 2021

    Tez_Clews 

    SEARCH accepts * and ? as wildcards, but not #.

    If you use Excel on Windows, you can use a custom VBA function:

    Function Check(s As String) As Boolean
        Dim re As Object
        Set re = CreateObject("VBScript.RegExp")
        re.Pattern = "[A-Za-z]{2}[0-9] to [A-Za-z]{2}[0-9]"
        Check = re.Test(s)
    End Function

    Let's say you want to apply conditional formatting to cells in column B, starting in B2.

    Use the following formula in your conditional formatting rule:

    =Check(B2)

     Don't forget to save the workbook as a macro-enabled workbook, and make sure that you allow macros when you open it.

Resources