LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Programmatically setting Conditional Formatting to a range of cells

Bill Renaud wrote:
I forgot to add that this code works only as long as the worksheet
has NOT been protected yet. If the worksheet has been protected, then
an error will be raised.

I rewrote the routine slightly as:

'----------------------------------------------------------------------
Public Sub FormatMarksRange()
Dim wsMarks As Worksheet
Dim blnProtected As Boolean
Dim rngMarks As Range

Set rngMarks = Range("Marks")
Set wsMarks = rngMarks.Parent
blnProtected = wsMarks.ProtectContents

If blnProtected Then wsMarks.Unprotect

With rngMarks
.FormatConditions.Delete

.FormatConditions.Add Type:=xlExpression, _
Formula1:="=CELL(""protect"",RC)"
.FormatConditions(1).Interior.ColorIndex = 24
End With

If blnProtected Then wsMarks.Protect
End Sub


Excellent. Thank you, Bill, for your clear explanation of RC and your
suggested enhancements to my routine. This is clearly the way to go rather
than an iterative solution.


 
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 on Range of Cells RoadKill Excel Worksheet Functions 7 March 30th 10 02:23 AM
Conditional Formatting to a RANGE of cells Wojo Excel Discussion (Misc queries) 2 October 1st 09 03:09 PM
suppress conditional formatting programmatically Janis Excel Discussion (Misc queries) 1 September 25th 07 12:06 AM
Setting up formatting for a range of cells [email protected] Excel Discussion (Misc queries) 0 January 4th 07 04:17 PM
Conditional formatting of a range of cells? [email protected] Excel Programming 0 December 18th 06 08:16 PM


All times are GMT +1. The time now is 02:15 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"