Conditional Formatting via VBA in Excel 2007

M

MrWinelover

New since version 2007 of Excel is the posibility to have conditional
formatting based on cells with specific text beginning with some predifined
text.
This is done by selecting Conditional Formatting (Home tab) > Manage
rules... Select "New Rule..." in the "Conditional Formatting Rules Manager"
window. In the "Newt Formatting Rule" windows choose the rule type "Format
only cell that contain" and edit the rule description by choosing "Specific
Text" in the left drop-dowm box and "beginning with" in the right drop-down
box. Give the text to check on in the textfield and click "OK"

Now the same conditional Formatting should be added via VBA but here's my
problem. It seems there is no information on the internet already.

Can someone help me further?
 
B

Bob Phillips

With Selection
.FormatConditions.Add Type:=xlTextString, _
String:="apple", _
TextOperator:=xlBeginsWith
.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
.FormatConditions(1).StopIfTrue = False
End With


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top