Bonjour,
Une proposition à étudier.
Voir feuille ESSAI 2.
Cdlt.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lastCol As Long
Dim rng As Range
lastCol = Cells(3, Columns.Count).End(xlToLeft).Column
Set rng = Range(Cells(4, 1), Cells(4, lastCol))
If Not Intersect(Target, rng) Is Nothing Then
If Target.Count > 1 Then GoTo Exit_Proc
DEMO2
End If
Exit_Proc:
Set rng = Nothing
Exit Sub
End Sub
Option Explicit
Option Private Module
Public Sub DEMO2()
Dim ws As Worksheet
Dim ch As ChartObject
Dim rngChart As Range
Dim s As Series
Dim tbl As Variant
Dim x As Long
Application.ScreenUpdating = False
Set ws = ActiveSheet
Set rngChart = ws.Cells(3, 1).CurrentRegion
On Error Resume Next
ws.ChartObjects(1).Delete
On Error GoTo 0
Set ch = ws.ChartObjects.Add( _
Left:=ws.Columns(2).Left, _
Top:=ws.Rows(6).Top, _
Width:=550, _
Height:=250)
With ch.Chart
.ChartType = xlColumnStacked
.SetSourceData Source:=rngChart, PlotBy:=xlRows
.HasTitle = True
.ChartTitle.Text = ws.Cells(1)
.HasLegend = False
'.Legend.Position = xlTop
.SetElement (msoElementDataTableShow)
With .Parent
.Placement = xlFreeFloating
.Name = "Graphique 2"
End With
End With
Set s = ch.Chart.FullSeriesCollection(1)
tbl = s.Values
's.Interior.Color = RGB(0, 176, 80)
For x = LBound(tbl) To UBound(tbl)
Select Case tbl(x)
Case Is > 0
s.Points(x).Format.Fill.ForeColor.RGB = RGB(0, 176, 80)
Case -1 To 0
s.Points(x).Format.Fill.ForeColor.RGB = RGB(255, 255, 0)
Case Else
s.Points(x).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
End Select
Next
Set s = Nothing: Set ch = Nothing: Set rngChart = Nothing: Set ws = Nothing
End Sub