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

Gareth

This should do the trick, change the color index to suit.

Sub Frmat()
Dim list As Range, crit As Range
Dim c
Set list = Range("A3:A101")
Set crit = Range("A2")
For Each c In list
If c.Value = crit Then
c.Interior.ColorIndex = 17
End If
Next c
End Sub

Regards
Peter
-----Original Message-----
When I apply the following format to the range A2:A101 it

works fine (if the
same value occurs more than once the cells are

highlighted).

=COUNTIF($A:$A,A2)1

I want to apply this format using code.

Thanks in advance.

Gareth


.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Conditional Formatting

I think you want to set the color to a default color if not set to colorindex
of 17; otherwise, all cells that can get set would probably eventually
be set to 17 from previous or current assignments.

Another method is an Change Event macro, an example in
http://www.mvps.org/dmcritchie/excel/event.htm#case
a bit of overkill, but then I think you would have done fine with
conditional formatting. Conditional Formatting has the advantage
of not caring how the values in the cell changes whether manually,
by formula, or by pasting in but does have the limitation of 3
sets of C.F per cell.
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Peter Atherton" wrote in message ...
Gareth

This should do the trick, change the color index to suit.

Sub Frmat()
Dim list As Range, crit As Range
Dim c
Set list = Range("A3:A101")
Set crit = Range("A2")
For Each c In list
If c.Value = crit Then
c.Interior.ColorIndex = 17
End If
Next c
End Sub

Regards
Peter
-----Original Message-----
When I apply the following format to the range A2:A101 it

works fine (if the
same value occurs more than once the cells are

highlighted).

=COUNTIF($A:$A,A2)1

I want to apply this format using code.

Thanks in advance.

Gareth


.



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
How can I convert conditional formatting into explicit formatting? Patrick Harris Excel Discussion (Misc queries) 0 April 9th 09 12:00 AM
Protect Cell Formatting including Conditional Formatting Mick Jennings Excel Discussion (Misc queries) 5 November 13th 07 05:32 PM
conditional Formatting based on cell formatting Totom Excel Worksheet Functions 3 January 20th 07 02:02 PM
conditional Formatting based on cell formatting Totom Excel Worksheet Functions 0 January 15th 07 04:35 PM
Conditional Formatting that will display conditional data BrainFart Excel Worksheet Functions 1 September 13th 05 05:45 PM


All times are GMT +1. The time now is 07:47 AM.

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"