SOLVED

Formula to find specific random text in a cell

%3CLINGO-SUB%20id%3D%22lingo-sub-2138791%22%20slang%3D%22en-US%22%3EFormula%20to%20find%20specific%20random%20text%20in%20a%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2138791%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20somewhat%20of%20a%20novice%20in%20Excel%20but%20I'm%20working%20on%20a%20project%20for%20work.%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20use%20a%20formula%20to%20conditional%20format%20a%20row%20when%20text%20is%20found%20in%20a%20cell%2C%20however%20the%20text%20although%20will%20always%20be%20the%20same%20format%20will%20be%20any%20combination%20of%20letters%2Fnumber...%3C%2FP%3E%3CP%3Ei.e.%20AB1%20to%20CD2%2C%20or%20AD2%20to%20CB1%2C%20or%20ZG3%20to%20YH7...%20will%20always%20have%20two%20letters%20and%20one%20number%20but%20could%20be%20any%20letters%20and%20numbers.%20It%20could%20also%20have%20leading%2Ftrailing%20text%20i.e.%20From%20AB1%20to%20CD2%2C%20or%20AB1%20to%20CD2%20transfer%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESelecting%20cells%20A6%20to%20L6%20as%20this%20is%20the%20range%20I%20am%20working%20with%20the%20data%20I%20am%20looking%20for%20in%20L6%2C%20I%20go%20in%20to%20conditional%20format%20and%20enter%20this%20formula...%3C%2FP%3E%3CP%3E%3DISNUMBER(SEARCH(%22%3F%3F%23%20to%20%3F%3F%23%22%2C%24L6))%20as%20I%20figured%20%3F%3F%20would%20look%20for%202%20letters%20and%20%23%20the%20one%20number.%3C%2FP%3E%3CP%3EI%20then%20format%20cells%20to%20highlight%20red.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20this%20formula%20isn't%20working%2C%20any%20ideas%20how%20I%20could%20do%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2138791%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2138853%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20to%20find%20specific%20random%20text%20in%20a%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2138853%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F968010%22%20target%3D%22_blank%22%3E%40Tez_Clews%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESEARCH%20accepts%20*%20and%20%3F%20as%20wildcards%2C%20but%20not%20%23.%3C%2FP%3E%0A%3CP%3EIf%20you%20use%20Excel%20on%20Windows%2C%20you%20can%20use%20a%20custom%20VBA%20function%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3EFunction%20Check(s%20As%20String)%20As%20Boolean%0A%20%20%20%20Dim%20re%20As%20Object%0A%20%20%20%20Set%20re%20%3D%20CreateObject(%22VBScript.RegExp%22)%0A%20%20%20%20re.Pattern%20%3D%20%22%5BA-Za-z%5D%7B2%7D%5B0-9%5D%20to%20%5BA-Za-z%5D%7B2%7D%5B0-9%5D%22%0A%20%20%20%20Check%20%3D%20re.Test(s)%0AEnd%20Function%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ELet's%20say%20you%20want%20to%20apply%20conditional%20formatting%20to%20cells%20in%20column%20B%2C%20starting%20in%20B2.%3C%2FP%3E%0A%3CP%3EUse%20the%20following%20formula%20in%20your%20conditional%20formatting%20rule%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DCheck(B2)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3BDon't%20forget%20to%20save%20the%20workbook%20as%20a%20macro-enabled%20workbook%2C%20and%20make%20sure%20that%20you%20allow%20macros%20when%20you%20open%20it.%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

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 will always be the same format will be any combination of letters/number...

i.e. AB1 to CD2, or AD2 to CB1, or ZG3 to YH7... will always have two letters and one number but could be any letters and numbers. It could also have leading/trailing text i.e. From AB1 to CD2, or AB1 to CD2 transfer

 

Selecting cells A6 to L6 as this is the range I am working with the data I am looking for in L6, I go in to conditional format and enter this formula...

=ISNUMBER(SEARCH("??# to ??#",$L6)) as I figured ?? would look for 2 letters and # the one number.

I then format cells to highlight red.

 

But this formula isn't working, any ideas how I could do this?

 

Thank you

2 Replies
best response confirmed by Tez_Clews (New Contributor)
Solution

@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.

@Hans Vogelaar 

 

Works perfectly thank you,

 

I thought VBA was the way to go as used it in another project but still very much a novice, was not aware of conditional format to VBA linking.

 

Managed to adapt it for different criteria so thank you again