LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Please check my code for conditional formatting

Hello all,

This is trippin' me out. I can't figure this out.

I'm trying to run this code on a set of cells (B30:B40):

Sub aaaaMacro1()
Dim prngCell As Range

Selection.FormatConditions.Delete

For Each prngCell In Selection
' Selection.FormatConditions.Add Type:=xlExpression, _
Formula1:="=ROUND(SUM(C30:II30),2)<0"
' prngCell.FormatConditions.Add xlExpression, , _
"=ROUND(SUM(" & Chr(prngCell.Column + 65) _
& prngCell.Row & ":II" And prngCell.Row & "),2)<0"
prngCell.FormatConditions.Add xlExpression, , _
"=ROUND(SUM(" & Chr(prngCell.Column + 65) _
& prngCell.Row & ":II" & prngCell.Row & "),2)<0"
' MsgBox prngCell.Address & vbCrLf & prngCell.FormatConditions(1).Formula1
With prngCell.FormatConditions(1).Font
.Bold = True
.Italic = False
.ColorIndex = 6
End With
prngCell.FormatConditions(1).Interior.ColorIndex = 3
Next prngCell
End Sub


My desired results is the following formulas in the conditional formatting of the coresponding cells:

Cell Address Conditional Formatting Formula
$B$30 =ROUND(SUM(C30:II30),2)<0
$B$31 =ROUND(SUM(C31:II31),2)<0
$B$32 =ROUND(SUM(C32:II32),2)<0
$B$33 =ROUND(SUM(C33:II33),2)<0
$B$34 =ROUND(SUM(C34:II34),2)<0
$B$35 =ROUND(SUM(C35:II35),2)<0
$B$36 =ROUND(SUM(C36:II36),2)<0
$B$37 =ROUND(SUM(C37:II37),2)<0
$B$38 =ROUND(SUM(C38:II38),2)<0
$B$39 =ROUND(SUM(C39:II39),2)<0
$B$40 =ROUND(SUM(C40:II40),2)<0


But my results are this (I verified this by clicking FormatConditional Formatting... on each cell AND the behavior of the
spreadsheet also verifies this):
NOTICE: The row reference in the formulas increase by 2 (only even numbered rows) while the actuall cell row only increases by 1

Cell Address Conditional Formatting Formula
$B$30 =ROUND(SUM(C30:II30),2)<0
$B$31 =ROUND(SUM(C32:II32),2)<0
$B$32 =ROUND(SUM(C34:II34),2)<0
$B$33 =ROUND(SUM(C36:II36),2)<0
$B$34 =ROUND(SUM(C38:II38),2)<0
$B$35 =ROUND(SUM(C40:II40),2)<0
$B$36 =ROUND(SUM(C42:II42),2)<0
$B$37 =ROUND(SUM(C44:II44),2)<0
$B$38 =ROUND(SUM(C46:II46),2)<0
$B$39 =ROUND(SUM(C48:II48),2)<0
$B$40 =ROUND(SUM(C50:II50),2)<0


THEN ON TOP OF IT ALL, if I run the following code:

Sub ReadFoldersFiles()
' Dim fso As New FileSystemObject
' Dim fsoFolder As Folder
' Dim fsoFolders As Folder
Dim prngCell As Range

' Set fsoFolder = fso.GetFolder("X:\----- (New)\2006_06_Data\Data Files\Not Imported")

Open "X:\----- (New)\2006_06_Data\CondFormattingFormulas.txt" For Output As #1

Write #1, "Cell Address", "Conditional Formatting Formula"

For Each prngCell In Selection
Write #1, prngCell.Address, "'" & prngCell.FormatConditions(1).Formula1
Next prngCell

Close #1
End Sub


THIS is the results I get in the resulting text file:

"Cell Address","Conditional Formatting Formula"
"$B$30","'=ROUND(SUM(C30:II30),2)<0"
"$B$31","'=ROUND(SUM(C31:II31),2)<0"
"$B$32","'=ROUND(SUM(C32:II32),2)<0"
"$B$33","'=ROUND(SUM(C33:II33),2)<0"
"$B$34","'=ROUND(SUM(C34:II34),2)<0"
"$B$35","'=ROUND(SUM(C35:II35),2)<0"
"$B$36","'=ROUND(SUM(C36:II36),2)<0"
"$B$37","'=ROUND(SUM(C37:II37),2)<0"
"$B$38","'=ROUND(SUM(C38:II38),2)<0"
"$B$39","'=ROUND(SUM(C39:II39),2)<0"
"$B$40","'=ROUND(SUM(C40:II40),2)<0"


WHAT THE HELL IS GOING ON HERE? I have my code set up correctly, don't I? I'm not telling it to skip every other one or use even
numbers only. How come it is entering one thing and telling me something different?

Thanks for any help anyone can provide,

Conan Kelly


 
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
how to check for ANY text when conditional formatting? Heather Excel Discussion (Misc queries) 4 September 19th 07 08:10 PM
conditional formatting via check box cedtech23[_13_] Excel Programming 1 July 20th 06 04:19 AM
Check box & conditional formatting Brent Excel Discussion (Misc queries) 4 January 10th 06 05:43 AM
conditional formatting w/ check for beginning odd or even [email protected] Excel Programming 4 December 20th 05 07:48 PM
Check Boxes and Conditional Formatting Steve[_71_] Excel Programming 2 November 29th 04 07:30 PM


All times are GMT +1. The time now is 01:24 AM.

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

About Us

"It's about Microsoft Excel"