View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
LiAD LiAD is offline
external usenet poster
 
Posts: 386
Default Colour format code

Hi,

I have a worksheet that I need to fill with five different colours, (none of
which are white) to represent a timeline of activities.

From cell I4 going vertically downwards I have the colours I want, blue,
green, brown, black and grey.
In cell J4 and going downwards I have the starting hours of the action
In cell K4 and going downwards I have the finishing hours for each action
Each cell going horizontally across from each line represents one hour
starting from L4, (starting from cell L2 I actually have a horizontal list
going 0, 1, 2 etc to represent the hours but I dont need this if its not
useful).

Is it possible to have a code that will fill in each cell starting from L4
with colour that is in I from the start time to the finish time. For example;

Blue 0 2 €“ excel fills in cells L4 and M4 in blue
Black 2 6 €“ excel fills in cells M5 to Q5 in black
Green 6 7 €“ excel fills in cells Q6 to R6 in green

The items that I need to keep changeable are the colours in each row, the
number of hours per task and the amount of cells that are coloured (i.e. on
some sheets there will be 10 rows coloured the others 30).

I actually have this code which works well and I can set an IF to change the
text to a number to drive the colours from, the bit I cant get is how to
make it fill more than one cell horizontally based on the start and finish
hours.

Is it possible to adapt this code to do that function?

Thanks a lot

Private Sub Worksheet_Change(ByVal Target As Range)
Set i = Range("I4:I20")
Set t = Target
If Intersect(t, i) Is Nothing Then Exit Sub
v = t.Value
If v 56 Then Exit Sub
Application.EnableEvents = False
Cells(t.Row, "L").Interior.ColorIndex = v
Cells(t.Row, "L").Font.ColorIndex = Target
Application.EnableEvents = True
End Sub