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

I'm relatively new to excel macros so bare with me. I've written a
simple formatting macro that I want to enhance. The macro is as
below.

Sub CondFormat()

Selection.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlGreater, _
Formula1:="=+$A$1"
Selection.FormatConditions(1).Font.ColorIndex = 2
Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlLess, _
Formula1:="=-$A$1"
Selection.FormatConditions(2).Font.ColorIndex = 2
Selection.FormatConditions(2).Interior.ColorIndex = 3

Range("A1").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

Range(myrange).Select

End Sub

The macro fails and gives me an error message if I run it on cells
already containing the conditional formatting. I'm not sure why. So,
I'd like to make the macro check first to see if this conditional
formatting already exists. If it does, then I want the macro to
delete the conditional formatting. If it doesn't already exist, then
execute the conditional formatting. Additionally, no matter if this
conditional formatting already exists or not, I'd like to always color
cell A1 with ColorIndex 6.

Can someone help? Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Formatting macro

Sub CondFormat()

With Selection
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlGreater, Formula1:="=+$A$1"
.FormatConditions(1).Font.ColorIndex = 2
.FormatConditions(1).Interior.ColorIndex = 3
.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlLess, Formula1:="=-$A$1"
.FormatConditions(2).Font.ColorIndex = 2
.FormatConditions(2).Interior.ColorIndex = 3
End With

With Range("A1").Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

Range(myrange).Select

End Sub


HTH
Paul
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Formatting macro

Just delete existinf formatting, that is

Sub CondFormat()

With Selection
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlGreater, _
Formula1:="=+$A$1"
.FormatConditions(1).Font.ColorIndex = 2
.FormatConditions(1).Interior.ColorIndex = 3
.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlLess, _
Formula1:="=-$A$1"
.FormatConditions(2).Font.ColorIndex = 2
.FormatConditions(2).Interior.ColorIndex = 3
End With

With Range("A1").Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

Range(myrange).Select

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"jbb16x99" wrote in message
om...
I'm relatively new to excel macros so bare with me. I've written a
simple formatting macro that I want to enhance. The macro is as
below.

Sub CondFormat()

Selection.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlGreater, _
Formula1:="=+$A$1"
Selection.FormatConditions(1).Font.ColorIndex = 2
Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlLess, _
Formula1:="=-$A$1"
Selection.FormatConditions(2).Font.ColorIndex = 2
Selection.FormatConditions(2).Interior.ColorIndex = 3

Range("A1").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

Range(myrange).Select

End Sub

The macro fails and gives me an error message if I run it on cells
already containing the conditional formatting. I'm not sure why. So,
I'd like to make the macro check first to see if this conditional
formatting already exists. If it does, then I want the macro to
delete the conditional formatting. If it doesn't already exist, then
execute the conditional formatting. Additionally, no matter if this
conditional formatting already exists or not, I'd like to always color
cell A1 with ColorIndex 6.

Can someone help? Thanks in advance.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Formatting macro



Sub CondFormat()
On Error Resume Next
Selection.formatconditions.Delete
On Error goto 0
Selection.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlGreater, _
Formula1:="=+$A$1"
Selection.FormatConditions(1).Font.ColorIndex = 2
Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlLess, _
Formula1:="=-$A$1"
Selection.FormatConditions(2).Font.ColorIndex = 2
Selection.FormatConditions(2).Interior.ColorIndex = 3

Range("A1").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

Range(myrange).Select

End Sub

--
Regards,
Tom Ogilvy


jbb16x99 wrote in message
om...
I'm relatively new to excel macros so bare with me. I've written a
simple formatting macro that I want to enhance. The macro is as
below.

Sub CondFormat()

Selection.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlGreater, _
Formula1:="=+$A$1"
Selection.FormatConditions(1).Font.ColorIndex = 2
Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlLess, _
Formula1:="=-$A$1"
Selection.FormatConditions(2).Font.ColorIndex = 2
Selection.FormatConditions(2).Interior.ColorIndex = 3

Range("A1").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

Range(myrange).Select

End Sub

The macro fails and gives me an error message if I run it on cells
already containing the conditional formatting. I'm not sure why. So,
I'd like to make the macro check first to see if this conditional
formatting already exists. If it does, then I want the macro to
delete the conditional formatting. If it doesn't already exist, then
execute the conditional formatting. Additionally, no matter if this
conditional formatting already exists or not, I'd like to always color
cell A1 with ColorIndex 6.

Can someone help? Thanks in advance.



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
formatting macro help [email protected] Excel Discussion (Misc queries) 2 March 10th 09 12:53 PM
Formatting using Macro simplymidori[_2_] Excel Discussion (Misc queries) 4 April 11th 08 12:22 AM
Formatting for a Macro Maggie Excel Discussion (Misc queries) 3 February 28th 07 02:00 AM
Formatting via a macro mike_vr Excel Discussion (Misc queries) 3 November 8th 06 04:19 PM
Macro for formatting Brian Clarke[_2_] Excel Programming 5 September 5th 03 01:55 PM


All times are GMT +1. The time now is 07:41 PM.

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"