Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
N L N L is offline
external usenet poster
 
Posts: 7
Default Inconsistent behavior when applying conditional formats

Believe it or not, I've already tried using "with .formatconditions(1)
and (2)". Even when I do that, both statements make changes on the
first format condition, EVEN IF I CHANGE THE NUMBERS! It's crazy.
Thanks for the suggestion, though. Any other ideas?


On Jul 22, 4:36 pm, "Gary Keramidas" <GKeramidasATmsn.com wrote:
here's a snippet that may help you, or maybe not. notice the (1) and (2) so it
can distinguish between which condition to apply it to.

With rng
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$d8$D$" & tbl1Lastrow
End With
With rng.FormatConditions(1).Borders(xlLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With rng.FormatConditions(1).Borders(xlRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With rng.FormatConditions(1).Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With rng.FormatConditions(1).Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
rng.FormatConditions(1).Interior.ColorIndex = 37

rng.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=MOD(ROW(),2)=0"
With rng.FormatConditions(2).Borders(xlLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With rng.FormatConditions(2).Borders(xlRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With rng.FormatConditions(2).Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With rng.FormatConditions(2).Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
rng.FormatConditions(2).Interior.ColorIndex = 2

--

Gary

"N L" wrote in message

...

Greetings,


I'm getting some inconsistent behavior when applying conditional
formats through VBA to a sheet. The worksheet is one of several in a
workbook, and some of the other worksheets in the workbook have
conditional formatting applied to them as well.


I am trying to apply two conditional formats to the same range of
cells. Basically, it makes numbers red if they're falling, and blue if
they're rising. In my VBA program, the first conditional format is
added, then the font style is applied properly. Then, the second
conditional format is added, but the font style is changed on the
FIRST conditional format. I cannot get VBA to apply the font style to
the second conditional format.


Here's the strange part: if I create a new workbook, and paste in the
same numbers from my problem workbook, the VBA Sub works correctly,
and the font styles are applied to the proper conditional formats.


Here is the code in question:


With ActiveSheet
With .Range(.Cells(3,
3), .Cells(.UsedRange.Rows.Count,
.UsedRange.Columns.Count)).FormatConditions.Add(Ty pe:=xlExpression,
Formula1:="=IF(RCRC[-1],TRUE,FALSE)")
With .Font
.Color = -1003520 ' blue
.TintAndShade = 0
End With
.StopIfTrue = False
End With
With .Range(.Cells(3,
3), .Cells(.UsedRange.Rows.Count,
.UsedRange.Columns.Count)).FormatConditions.Add(Ty pe:=xlExpression,
Formula1:="=IF(RC<RC[-1],TRUE,FALSE)")
With .Font
.Color = -16776961 ' red
.TintAndShade = 0
End With
.StopIfTrue = False
End With
End With


Could it be that I'm hitting a limit on the number of conditional
formats available in a single workbook addressable by VBA?


Could there be some other part of the program that makes VBA only able
to change the properties of one conditional format?


Any other ideas would be valued.


N Lee

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Inconsistent behavior when applying conditional formats

On Jul 23, 9:31 am, N L wrote:
Believe it or not, I've already tried using "with .formatconditions(1)
and (2)". Even when I do that, both statements make changes on the
first format condition, EVEN IF I CHANGE THE NUMBERS! It's crazy.
Thanks for the suggestion, though. Any other ideas?

On Jul 22, 4:36 pm, "Gary Keramidas" <GKeramidasATmsn.com wrote:

here's a snippet that may help you, or maybe not. notice the (1) and (2) so it
can distinguish between which condition to apply it to.


With rng
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$d8$D$" & tbl1Lastrow
End With
With rng.FormatConditions(1).Borders(xlLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With rng.FormatConditions(1).Borders(xlRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With rng.FormatConditions(1).Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With rng.FormatConditions(1).Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
rng.FormatConditions(1).Interior.ColorIndex = 37


rng.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=MOD(ROW(),2)=0"
With rng.FormatConditions(2).Borders(xlLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With rng.FormatConditions(2).Borders(xlRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With rng.FormatConditions(2).Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With rng.FormatConditions(2).Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
rng.FormatConditions(2).Interior.ColorIndex = 2


--


Gary


"N L" wrote in message


...


Greetings,


I'm getting some inconsistent behavior when applying conditional
formats through VBA to a sheet. The worksheet is one of several in a
workbook, and some of the other worksheets in the workbook have
conditional formatting applied to them as well.


I am trying to apply two conditional formats to the same range of
cells. Basically, it makes numbers red if they're falling, and blue if
they're rising. In my VBA program, the first conditional format is
added, then the font style is applied properly. Then, the second
conditional format is added, but the font style is changed on the
FIRST conditional format. I cannot get VBA to apply the font style to
the second conditional format.


Here's the strange part: if I create a new workbook, and paste in the
same numbers from my problem workbook, the VBA Sub works correctly,
and the font styles are applied to the proper conditional formats.


Here is the code in question:


With ActiveSheet
With .Range(.Cells(3,
3), .Cells(.UsedRange.Rows.Count,
.UsedRange.Columns.Count)).FormatConditions.Add(Ty pe:=xlExpression,
Formula1:="=IF(RCRC[-1],TRUE,FALSE)")
With .Font
.Color = -1003520 ' blue
.TintAndShade = 0
End With
.StopIfTrue = False
End With
With .Range(.Cells(3,
3), .Cells(.UsedRange.Rows.Count,
.UsedRange.Columns.Count)).FormatConditions.Add(Ty pe:=xlExpression,
Formula1:="=IF(RC<RC[-1],TRUE,FALSE)")
With .Font
.Color = -16776961 ' red
.TintAndShade = 0
End With
.StopIfTrue = False
End With
End With


Could it be that I'm hitting a limit on the number of conditional
formats available in a single workbook addressable by VBA?


Could there be some other part of the program that makes VBA only able
to change the properties of one conditional format?


Any other ideas would be valued.


N Lee


Still seeking a solution. Does anyone have any idea why Excel would
confuse these two FormatConditions?
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inconsistent behavior of listboxes vezerid Excel Programming 0 April 29th 08 01:21 PM
Inconsistent behavior using VLOOKUP Andrew[_56_] Excel Programming 4 February 12th 08 10:23 PM
Inconsistent Macro Behavior Sarah K Excel Discussion (Misc queries) 4 November 1st 05 10:36 PM
Inconsistent macro behavior davegb Excel Programming 2 June 21st 05 11:19 PM
Inconsistent Behavior on Web vs. Local Disk D. A. Gray Excel Programming 0 July 27th 03 08:13 PM


All times are GMT +1. The time now is 10:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"