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: 22
Default Programmatically setting Conditional Formatting to a range of cells

I wish to programmatically set the conditional formatting of a range of
cells to highlight those cells that are locked.

I can readily do this 'manually' by highlighting a range of cells (say
A1:A7) and then entering a conditional format formula of
=CELL("protect",A1) - this assumes that when selecting the range A1:A7 the
first cell selected was A1. Excel automatically updates the second
parameter of the cell function so that, for example, the conditional format
formula in cell A7 is =CELL("protect",A7).

Programmatically in VB I can use the following (determined by recording a
macro as I did the above).

1- Range("A1:A7").Select
2- Range("A1").Activate 'is this necessary?

3- Selection.FormatConditions.Delete

4- Selection.FormatConditions.Add Type:=xlExpression, Formula1:=
"=CELL(""protect"",A1)"
5- Selection.FormatConditions(1).Interior.ColorIndex = 24

However, what I am not clear about is how to deal with a named range, such
as "Marks". The first statement above becomes:

1- Range("Marks").Select

How do I need to modify the reference to A1 in lines 2 and 4?


 
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 11:51 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"