conditional formatting with WILDCARD

MR3

Board Regular
Joined
Jun 10, 2008
Messages
175
is it possible to format a row with the condition NAME_* where name is always the same prefix?
thus if a row contains this particular prefix it will flood fill the entire cell
 
Last edited:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi,

Maybe this

Conditional Formatting > New Rule > Use a formula ...
insert this formula
=SEARCH("NAME_",$A1)=1
pick the format you want

HTH

M.
 
Upvote 0
But I want the code via a vb script so I can add it to my module t evaluate a specific row or column
 
Upvote 0
Does this do what you want?

If you are using Excel 2010 I don't think you need the ".Select" line.

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> ApplyCF()<br>    <SPAN style="color:#00007F">With</SPAN> Columns("C")<br>        .Select <SPAN style="color:#007F00">'2007 & earlier</SPAN><br>        .FormatConditions.Delete<br>        .FormatConditions.Add Type:=xlExpression, _<br>            Formula1:="=LEFT(C1,5)=""NAME_"""<br>        .FormatConditions(1).Interior.ColorIndex = 35<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
This i got with the macro recorder to highlight (light grey) the rows in the range C1:F10 whose cells in column C begin with NAME_


Code:
Sub Macro3()
'
' Macro3 Macro
'
'
    Range("C1:F10").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=SEARCH(""NAME_"",$C1)=1"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = -0.14996795556505
    End With
    Selection.FormatConditions(1).StopIfTrue = False
End Sub

Maybe yopu can adjust it to your real data

HTH

M.
 
Upvote 0
THANKS Peter your code worked as intended.
Marcelo i will try your code next.
 
Upvote 0
Does this do what you want?

If you are using Excel 2010 I don't think you need the ".Select" line.

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> ApplyCF()<br>****<SPAN style="color:#00007F">With</SPAN> Columns("C")<br>********.Select <SPAN style="color:#007F00">'2007 & earlier</SPAN><br>********.FormatConditions.Delete<br>********.FormatConditions.Add Type:=xlExpression, _<br>************Formula1:="=LEFT(C1,5)=""NAME_"""<br>********.FormatConditions(1).Interior.ColorIndex = 35<br>****<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

Hey Peter,
is there a way a user could Enter what the prefix should be, via a pop window in the vb script?
So if the user entered it I think it would have to auto fill in the length of the string entered and then it the script would need to search for and highlight the string entered in that particular column.
 
Upvote 0
Try this:

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> ApplyCF()<br>    <SPAN style="color:#00007F">Dim</SPAN> Prefix <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> L <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    <SPAN style="color:#00007F">Const</SPAN> Fbase <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN> = "=LEFT(C1,#)=""^"""<br>    <br>    Prefix = InputBox("What prefix?")<br>    L = Len(Prefix)<br>    <SPAN style="color:#00007F">If</SPAN> L > 0 <SPAN style="color:#00007F">Then</SPAN><br>        <SPAN style="color:#00007F">With</SPAN> Columns("C")<br>            .Select <SPAN style="color:#007F00">'2007 & earlier</SPAN><br>            .FormatConditions.Delete<br>            .FormatConditions.Add Type:=xlExpression, _<br>                Formula1:=Replace(Replace(Fbase, "#", L), "^", Prefix)<br>            .FormatConditions(1).Interior.ColorIndex = 35<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top