Hello,
i made a nice and as i thought, very elegant array macro some years ago to give a gantt chart index colours (3, 45, 4) linked to its status information. What i tried in vain was to replace the index colours with RGB colurs of Status cells (please see my example) and to insert some columns with other information, but no impact to the coloring of the gantt chart . Is there an easy way to replace index colours wit the RGB value of a given status array (in this case 8 colours)? Can you help me?
Color Gantt Chart with RGB colours instead of index colors
-
- 4StarLounger
- Posts: 415
- Joined: 29 Mar 2010, 11:50
- Location: Vienna, Austria
Color Gantt Chart with RGB colours instead of index colors
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Color Gantt Chart with RGB colours instead of index colo
Instead of using
you can use
where ... is an RGB color.
Even better, replace
with
Code: Select all
Selection.Interior.ColorIndex = Farbe
Code: Select all
Selection.Interior.Color = ...
Even better, replace
Code: Select all
ActiveSheet.ChartObjects("Diagramm 8").Activate
ActiveChart.SeriesCollection(2).Points(z).Select
Selection.Interior.ColorIndex = Farbe
Code: Select all
ActiveSheet.ChartObjects("Diagramm 8").Chart.SeriesCollection(2).Points(z).Interior.Color = ...
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 415
- Joined: 29 Mar 2010, 11:50
- Location: Vienna, Austria
Re: Color Gantt Chart with RGB colours instead of index colo
ok, but how can i take the RGB array colours (in this case now in worksheet Plan in cells G4:G11)?
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Color Gantt Chart with RGB colours instead of index colo
Try this:
Note: cell G6 has a theme color instead of an RGB color. Better assign an RGB color to G6, otherwise the colors won't match.
Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c1 As Range
Dim c2 As Range
If Not Intersect(Range("E4:E15"), Target) Is Nothing Then
For Each c1 In Intersect(Range("E4:E15"), Target)
Set c2 = Range("G4:G11").Find(What:=c1.Value, LookAt:=xlWhole)
If c2 Is Nothing Then
c1.Interior.ColorIndex = xlColorIndexNone
Else
c1.Interior.Color = c2.Interior.Color
End If
Next c1
End If
End Sub
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 415
- Joined: 29 Mar 2010, 11:50
- Location: Vienna, Austria
Re: Color Gantt Chart with RGB colours instead of index colo
ok, now it changes the cell color, i will test it so to change the chart colors as well
-
- Administrator
- Posts: 78545
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Color Gantt Chart with RGB colours instead of index colo
Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c1 As Range
Dim c2 As Range
Dim z As Long
If Not Intersect(Range("E4:E15"), Target) Is Nothing Then
For Each c1 In Intersect(Range("E4:E15"), Target)
z = c1.Row - 3
Set c2 = Range("G4:G11").Find(What:=c1.Value, LookAt:=xlWhole)
If c2 Is Nothing Then
c1.Interior.ColorIndex = xlColorIndexNone
Me.ChartObjects("Diagramm 8").Chart.SeriesCollection(2) _
.Points(z).Interior.ColorIndex = xlColorIndexNone
Else
c1.Interior.Color = c2.Interior.Color
Me.ChartObjects("Diagramm 8").Chart.SeriesCollection(2) _
.Points(z).Interior.Color = c2.Interior.Color
End If
Next c1
End If
End Sub
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 415
- Joined: 29 Mar 2010, 11:50
- Location: Vienna, Austria
Re: Color Gantt Chart with RGB colours instead of index colo
cool, thank you, Hans.