Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 271
Default Conditional Formatting Code

I recorded this code but I need it to do more and work a little differently.
I need it to first remove any existing "Conditional" formatting. Not all
formatting, just remove the existing conditional formatting. I then need to
add the conditional formatting as detailed below.

Also, my intent was to copy the formatting from the first cell into others.
I need it to do all this with out selecting (.Select). Please help.

Sheets("Travel").Range("R7:R8").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=(IF(R90,0,IF(SUM(T9)0,1,0)))0"

Selection.FormatConditions(Selection.FormatConditi ons.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
Selection.Copy
Range("R9:R10,R12:R13,R15:R16").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False



--
Thanks
Shawn
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 257
Default Conditional Formatting Code

Doing it without Select is easy; wherever it says "<something
something.Select" change it to "Set <variable name to <something
something", and then wherever it says "Selection.<anything" change it to
"<variable name.<anything". So, for example, the first two lines of your
recording can be changed to

Set oRng = Sheets("Travel").Range("R7:R8")
oRng.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND(R9<=0,SUM(T9)0)"

(You can use your IF functions if you want, but I think mine is simpler.)
oRng, in my example, is simply a variable name I picked to hold the specified
range, or any other object for that matter; you can pick another name if you
prefer.

To do this to a larger area you can set a larger range, or you can set up a
loop to do it in different areas throughout your sheet. I'm not sure of the
details.

Feel free to ask more questions; the above is pretty sketchy, on the
assumption that you know the basics and just need a hint or two.

--- "Shawn" wrote:
I recorded this code but I need it to do more and work a little differently.
I need it to first remove any existing "Conditional" formatting. Not all
formatting, just remove the existing conditional formatting. I then need to
add the conditional formatting as detailed below.

Also, my intent was to copy the formatting from the first cell into others.
I need it to do all this with out selecting (.Select). Please help.

Sheets("Travel").Range("R7:R8").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=(IF(R90,0,IF(SUM(T9)0,1,0)))0"

Selection.FormatConditions(Selection.FormatConditi ons.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
Selection.Copy
Range("R9:R10,R12:R13,R15:R16").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

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
Conditional Formatting Code JoAnn Excel Programming 4 June 25th 08 05:56 PM
Conditional Formatting vb code beverlydawn Excel Programming 1 March 5th 08 07:41 PM
Conditional Formatting using code Ayo Excel Discussion (Misc queries) 5 February 29th 08 01:09 PM
Conditional Formatting to VBA code Dean P. Excel Programming 1 December 18th 07 05:03 PM
Need help to changes a conditional formatting code.... BeSmart Excel Programming 7 September 14th 04 01:27 AM


All times are GMT +1. The time now is 02:44 PM.

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"