Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default Formatting Cells Dependent on Contents

You are limited to 56 colors in a worksheet.

Add a Change event to the sheets code page - right click
on the sheet tab & select View Code

Private Sub Worksheet_Change(ByVal Target As Range)
Target.Interior.ColorIndex = GetColor(Target.Value)
End Sub

Now that you're in the IDE, add a standard module with
this code:


Function GetColor(sText As String) As Long
Dim cl As Long
On Error Resume Next
cl = Application.WorksheetFunction.VLookup(sText,
ThisWorkbook.Names("ColorList").RefersToRange, 2, False)
Err.Clear
On Error GoTo 0
GetColor = cl
End Function


add another worksheet.
in column A add the text list that you want and in B the
corresponing index - must be 0 to 56
range name the list ColorList

When you enter something on your first sheet, the change
event sets the cells color depending on the return value
from the function. The event handler passes the cell's
new value to the function.

The function simply uses the vlookup function to match
the text in A and get a numbet from B. Unfortunately the
VLookUp function generates an error condition if there's
no match, so our code skips this.


Simple hey?
If anyone wants my workbook, email me directly

Patrick Molloy
Microsoft Excel MVP






-----Original Message-----
Is their an easy piece of code which could be used on an
entire worksheet to format the cells dependent on their
content. I.e if a cell contains the text 'house' then

the
cell has a red background etc. for about 50 conditions.
This is similar to conditional formating but i need more
than 3 conditions and the code should update the colour

of
the cell if the content changes?

I am sure this must be fairly simple, but when i have
aksed in the past the code i received was far too

complex
and did not update? I am fairly new to the code side of
Excel so please keep any examples simple.

Danny.
.

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
Directing cell contents to one of two cells dependent on its value Debi Excel Worksheet Functions 1 April 15th 10 03:13 PM
directing cell contents dependent on its value Debi Excel Worksheet Functions 2 April 15th 10 09:58 AM
how do I fix formatting mistakes: cells and contents are wavy superteacher Excel Worksheet Functions 0 March 25th 09 03:10 AM
Data Validation list dependent on contents of another cell Scorer150 Excel Discussion (Misc queries) 2 February 7th 08 12:13 AM
Formatting Cells Dependent on Contents Bill Manville Excel Programming 0 November 27th 03 01:36 PM


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