J'ai bossé un peu sur le fichier aujourd'hui mais je le trouve instable, en effet, j'aimerais que vous me corrigiez:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Coef As Double
Dim Sh As Shape
If Not Intersect(Range("A1,A2,A3,E10:E11"), Target) Is Nothing Then
Coef = Range("E11")
'
' Effacement des barres crées
'
For Each Sh In ActiveSheet.Shapes
If Sh.Name Like "Rectangle *" Then
If Sh.TopLeftCell.Column = Sh.BottomRightCell.Column Then ' On efface les barres dont le Haut et le bas sont dans la même colonne
Sh.Delete
End If
End If
Next Sh
'
' Refait les barres
'
If Range("A1") > 0 Then
With Range("G10")
ActiveSheet.Shapes.AddShape(msoShapeRectangle, .Left + (.Width / 2) - 10, _
.Top + .Height - (Range("A1") * Coef), _
20, _
Range("A1") * Coef).Fill.ForeColor.SchemeColor = 32
End With
End If
If Range("E10") > 0 Then
With Cells(10, "H")
ActiveSheet.Shapes.AddShape(msoShapeRectangle, .Left + (.Width / 2) - 10, _
.Top + .Height - (Range("E10") * Coef), _
20, _
Range("E10") * Coef).Fill.ForeColor.SchemeColor = 32
End With
End If
If Range("A2") > 0 Then
With Range("I10")
ActiveSheet.Shapes.AddShape(msoShapeRectangle, .Left + (.Width / 2) - 10, _
.Top + .Height - (Range("A2") * Coef), _
20, _
Range("A2") * Coef).Fill.ForeColor.SchemeColor = 32
End With
End If
If Range("A3") > 0 Then
With Range("F10")
ActiveSheet.Shapes.AddShape(msoShapeRectangle, .Left + (.Width / 2) - 10, _
.Top + .Height - (Range("A3") * Coef), _
20, _
Range("A3") * Coef).Fill.ForeColor.SchemeColor = 8
End With
End If
End If
End Sub
j'ai fait ça, donc si je comprend bien :
- si je veux mettre une autre cellule en tant que coeff, je change la ou c'est écrit E11 par ma nouvelle case (rien d'autres a faire) ?
- si je veux rajouter une barre, je dois premierement marque la case ici :
If Not Intersect(Range("A1,A2,A3,E10:E11"), Target) Is Nothing Then
puis je change ici lorsque je rajoute une barre :
If Range("[color=#FF0000]A3[/color]") > 0 Then
With Range("F10")
ActiveSheet.Shapes.AddShape(msoShapeRectangle, .Left + (.Width / 2) - 10, _
.Top + .Height - (Range("[color=#FF0000]A3[/color]") * Coef), _
20, _
Range("[color=#FF0000]A3[/color]") * Coef).Fill.ForeColor.SchemeColor = 8
End With
End If
ou dois je faire autre chose ?
(je dis que c'est instable car toutes les barres ne changent pas de tailles en fonction de du coeff que je mets)