PC Review


Reply
Thread Tools Rate Thread

4 conditional formats

 
 
=?Utf-8?B?YW5keQ==?=
Guest
Posts: n/a
 
      26th Jun 2007
after having recorded a macro containing 3 conditional formats, i retrieve
the following code in VBA Editor :

Range("C24:AF54,C60:AF90,C96:AF126").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="1"
Selection.FormatConditions(1).Font.ColorIndex = 11
Selection.FormatConditions(1).Interior.ColorIndex = 11
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="0,5"
Selection.FormatConditions(2).Font.ColorIndex = 41
Selection.FormatConditions(2).Interior.ColorIndex = 41
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="-0,5"
Selection.FormatConditions(3).Font.ColorIndex = 15
Selection.FormatConditions(3).Interior.ColorIndex = 15
Sheets("Test2").Select

after the "Selection.FormatConditions(3).Interior.ColorIndex = 15" line, i
try adding a fourth conditional format in VBA as follows:

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="-1"
Selection.FormatConditions(4).Font.ColorIndex = 20
Selection.FormatConditions(4).Interior.ColorIndex = 20

However, when i run the macro, an error is returned at the
" Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="-1" " line

is it possible to add a fourth (fifth,..) conditional format ?

thanks
andy
 
Reply With Quote
 
 
 
 
meh2030@gmail.com
Guest
Posts: n/a
 
      26th Jun 2007
On Jun 26, 10:50 am, andy <a...@discussions.microsoft.com> wrote:
> after having recorded a macro containing 3 conditional formats, i retrieve
> the following code in VBA Editor :
>
> Range("C24:AF54,C60:AF90,C96:AF126").Select
> Selection.FormatConditions.Delete
> Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
> Formula1:="1"
> Selection.FormatConditions(1).Font.ColorIndex = 11
> Selection.FormatConditions(1).Interior.ColorIndex = 11
> Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
> Formula1:="0,5"
> Selection.FormatConditions(2).Font.ColorIndex = 41
> Selection.FormatConditions(2).Interior.ColorIndex = 41
> Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
> Formula1:="-0,5"
> Selection.FormatConditions(3).Font.ColorIndex = 15
> Selection.FormatConditions(3).Interior.ColorIndex = 15
> Sheets("Test2").Select
>
> after the "Selection.FormatConditions(3).Interior.ColorIndex = 15" line, i
> try adding a fourth conditional format in VBA as follows:
>
> Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
> Formula1:="-1"
> Selection.FormatConditions(4).Font.ColorIndex = 20
> Selection.FormatConditions(4).Interior.ColorIndex = 20
>
> However, when i run the macro, an error is returned at the
> " Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
> Formula1:="-1" " line
>
> is it possible to add a fourth (fifth,..) conditional format ?
>
> thanks
> andy


The "FormatConditions Collection Object" in the VBE help states the
following:
Represents the collection of conditional formats for a single range.
The FormatConditions collection can contain up to three conditional
formats. Each format is represented by a FormatCondition object.

So, you can only have 3 conditional formats if you are using the
conditional formatting option via Excel. However, since you are using
VBA you can create a loop and add your logical test with corresponding
color index. This way you can create as as many "conditional formats"
as you want.

I hope this helps.

Matt

 
Reply With Quote
 
=?Utf-8?B?YW5keQ==?=
Guest
Posts: n/a
 
      27th Jun 2007
thanks!
i used a select case statement to add a fourth conditional format and it
works.

"(E-Mail Removed)" wrote:

> On Jun 26, 10:50 am, andy <a...@discussions.microsoft.com> wrote:
> > after having recorded a macro containing 3 conditional formats, i retrieve
> > the following code in VBA Editor :
> >
> > Range("C24:AF54,C60:AF90,C96:AF126").Select
> > Selection.FormatConditions.Delete
> > Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
> > Formula1:="1"
> > Selection.FormatConditions(1).Font.ColorIndex = 11
> > Selection.FormatConditions(1).Interior.ColorIndex = 11
> > Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
> > Formula1:="0,5"
> > Selection.FormatConditions(2).Font.ColorIndex = 41
> > Selection.FormatConditions(2).Interior.ColorIndex = 41
> > Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
> > Formula1:="-0,5"
> > Selection.FormatConditions(3).Font.ColorIndex = 15
> > Selection.FormatConditions(3).Interior.ColorIndex = 15
> > Sheets("Test2").Select
> >
> > after the "Selection.FormatConditions(3).Interior.ColorIndex = 15" line, i
> > try adding a fourth conditional format in VBA as follows:
> >
> > Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
> > Formula1:="-1"
> > Selection.FormatConditions(4).Font.ColorIndex = 20
> > Selection.FormatConditions(4).Interior.ColorIndex = 20
> >
> > However, when i run the macro, an error is returned at the
> > " Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
> > Formula1:="-1" " line
> >
> > is it possible to add a fourth (fifth,..) conditional format ?
> >
> > thanks
> > andy

>
> The "FormatConditions Collection Object" in the VBE help states the
> following:
> Represents the collection of conditional formats for a single range.
> The FormatConditions collection can contain up to three conditional
> formats. Each format is represented by a FormatCondition object.
>
> So, you can only have 3 conditional formats if you are using the
> conditional formatting option via Excel. However, since you are using
> VBA you can create a loop and add your logical test with corresponding
> color index. This way you can create as as many "conditional formats"
> as you want.
>
> I hope this helps.
>
> Matt
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Formats, how to scroll and view all formats? Bill E Microsoft Excel Worksheet Functions 0 12th May 2010 07:58 PM
> 6 CONDITIONAL FORMATS Songoku Microsoft Excel Misc 7 4th Jul 2008 12:47 AM
Conditional formats- paste special formats? =?Utf-8?B?amNhcm5leQ==?= Microsoft Excel Misc 1 1st Nov 2007 06:37 PM
paste conditional formats as formats =?Utf-8?B?bGVv?= Microsoft Excel Misc 2 5th Jul 2007 10:06 AM
More Than 3 Conditional Formats SamuelT Microsoft Excel Misc 1 21st Jun 2006 02:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:19 PM.