View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Gary''s Student
 
Posts: n/a
Default Conditional Formatting

Then a small update:

Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim i As String
If Intersect(Range("A1:A10"), Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
Target.Select
i = Selection.Value
If i = "p" Then
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
Application.EnableEvents = True
End Sub

Here we are only looking for the user to enter p. The colorindex=3 sets the
background colour to red. If you want other letters to trigger other
colours, then replicate the IF structure with a different letter and a
different colorindex.


With regard to entering and using this type of macro, see:


http://www.mvps.org/dmcritchie/excel/event.htm
--
Gary''s Student


"Ian.UK" wrote:

Hi,

Thanks for the feedback - going to need a little bit more help with this
unfortunately, as macros are not my forte!

What part of this macro actually changes the colour of the cell?

And when you say integers, would this this macro actually work with letters
i.e. if I wanted to a cell containing the letter P to be red?

Many thanks,

Ian

"Gary''s Student" wrote:

This can be accomplished by using the worksheet change event. The following
macro monitors changes in A1:A20 and set the background colour:

Sub Worksheet_Change(ByVal Target As Excel.Range)
If Intersect(Range("A1:A10"), Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
Target.Select
i = Selection.Value
With Selection.Interior
.ColorIndex = i
.Pattern = xlSolid
End With
Application.EnableEvents = True
End Sub

The sample macro only works with integers and assigns colours based upon the
integers. You could modify it to operate in a more general way.
__________________Have a good day!
Gary's Student


"Ian.UK" wrote:

Hi,

Is it possible to introduce more than 3 conditions (via conditional
formatting) onto a single spreadsheet?

I have a spreadsheet with 9 columns - the first is for name, then 1st
choice, 2nd choice etc etc...up to 8th choice. There are 8 different things
that could appear in each cell on the same row - and I would like the cell to
change colour automatically according to what appears in it. This would
obviously require 8 conditions - but I seem limited to 3.

Is there a way to increase the number of permissible conditions, or can
anyone think of a way I can achieve this without conditions?

Thanks,

Ian