Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / October 2007

Tip: Looking for answers? Try searching our database.

Help with conditional formating

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
PO - 30 Oct 2007 13:00 GMT
Hi,

I'm running Excel 2003, Sp2.
I'm using conditional formatting to change the background color on some
worksheet cells:

Cellvalue = Color
============
A = red
B = green
C = blue

This works fine but due to changes in the workbook I now also need to be
able to format a fourth cellvalue,  D = yellow. The built-in function
however only lets me set up conditional formatting for three values.

Is there any way to achieve this?

TIA
Pete
Bernie Deitrick - 30 Oct 2007 14:07 GMT
Pete,

Use simple formatting to color the cell yellow.  CF will take over for the first three values, and
it will be yellow for D.  If you have more than that, or need to have a different color for blank
(which would be a fifth condition), then you will need to use the worksheet_change event with code
to control the color fill.

HTH,
Bernie
MS Excel MVP

> Hi,
>
[quoted text clipped - 15 lines]
> TIA
> Pete
PO - 30 Oct 2007 15:26 GMT
Bernie,

Could you give an example of how the formating code would look like?

Regards
Pete

> Pete,
>
[quoted text clipped - 28 lines]
>> TIA
>> Pete
Bernie Deitrick - 30 Oct 2007 15:38 GMT
Pete,

The example code below will apply colors to column A.  Copy the code, right-click the sheet tab,
select "View Code" and paste the code into the window that appears.

HTH,
Bernie
MS Excel MVP

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myCell As Range
Dim myR As Range

Set myR = Intersect(Target, Range("A:A"))

If myR Is Nothing Then Exit Sub

Application.EnableEvents = False
For Each myCell In myR
  If myCell.Value = "A" Then myCell.Interior.ColorIndex = 3
  If myCell.Value = "B" Then myCell.Interior.ColorIndex = 41
  If myCell.Value = "C" Then myCell.Interior.ColorIndex = 50
  If myCell.Value = "D" Then myCell.Interior.ColorIndex = 6
  If myCell.Value = "E" Then myCell.Interior.ColorIndex = 46
  If myCell.Value = "" Then myCell.Interior.ColorIndex = xlNone
Next myCell
Application.EnableEvents = True
End Sub

> Bernie,
>
[quoted text clipped - 33 lines]
>>> TIA
>>> Pete
PO - 30 Oct 2007 15:44 GMT
Thanks Bernie, works perfect!

/Pete

> Pete,
>
[quoted text clipped - 66 lines]
>>>> TIA
>>>> Pete
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.