'-------------------------------------------------
'Colorise les Shapes de la carte selon les données
'de "tableau1" et les couleurs de "tableau2"
'-------------------------------------------------
Sub ColoriseShapesSurDonnées()
Dim Sh As Shape
Dim ShapeName As String
Dim Pourcentage As Single
Dim Color As Long
Dim Tbl As Range 'ListObject'!!!!!!!!!!!!!!!!!!!!!!!!
Dim TabDept() As Variant
Dim TabColor() As Variant
Dim i As Integer
Dim j As Integer
Dim ErrNumber As Variant
'Chargement des tableaux en mémoire
'Set Tbl = Range("tableau1").Parent.ListObjects("tableau1")'!!!!!!!!!!!!!!!!!!!!!!!!
'TabDept = Tbl.DataBodyRange.Value'!!!!!!!!!!!!!!!!!!!!!!!!
'Set Tbl = Range("tableau2").Parent.ListObjects("tableau2")'!!!!!!!!!!!!!!!!!!!!!!!!
'TabColor = Tbl.DataBodyRange.Value'!!!!!!!!!!!!!!!!!!!!!!!!
Set Tbl = Range("tableau1")
TabDept = Tbl.Value
Set Tbl = Range("tableau2")
TabColor = Tbl.Value
Call DécoloriseShapes
'Parcours du tableau des Départements
For i = 1 To UBound(TabDept)
'Nom de la Shape correspondante au département
ShapeName = ShapeNamePrefix & TabDept(i, 1)
'Pourcentage du département
Pourcentage = 0
If IsNumeric(TabDept(i, 3)) Then Pourcentage = TabDept(i, 3)
'Parcours du tableau des pourcentages
For j = 1 To UBound(TabColor)
If TabColor(j, 1) > Pourcentage Then Exit For
Next j
If j > 1 Then j = j - 1
'ActiveSheet.Shapes(ShapeName).Fill.ForeColor.RGB = RGB(0, 176, 240)
'Color = Tbl.DataBodyRange.Cells(j, 2).Interior.Color'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Color = Tbl.Cells(j, 2).Interior.Color
On Error Resume Next
ActiveSheet.Shapes(ShapeName).Fill.ForeColor.RGB = Color 'RGB(GetRGBFromLong(Color, "R"), _
'GetRGBFromLong(Color, "G"), _
'GetRGBFromLong(Color, "B"))
ErrNumber = Err.Number
On Error GoTo 0
If ErrNumber Then MsgBox "Shape <" & ShapeName & "> inexistante."
Next i
End Sub
'---------------------------------------------------------
'Retourne les composantes R, G, B à partir d'un Color Long
'---------------------------------------------------------
'Function GetRGBFromLong(longColor As Long, RGB As String) As Integer
'Select Case RGB
'Case "R"
' GetRGBFromLong = (longColor Mod 256)
'Case "G"
'GetRGBFromLong = (longColor \ 256) Mod 256
'Case "B"
'GetRGBFromLong = (longColor \ 65536) Mod 256
'End Select
'End Function