Sub test_ok()
Dim tab_SHP() As Variant, i&, shp As Shape
With ActiveSheet
ReDim tab_SHP(1 To .Shapes.Count)
For i = 1 To .Shapes.Count
If .Shapes(i).AutoShapeType = 1 Then ' 1=Rectangle
tab_SHP(i) = .Shapes(i).Name
End If
Next
Set shp = .Shapes.Range(tab_SHP).Group
End With
shp.Name = "TEST"
End Sub
Sub MiseEnforme_Rack_Plan_G_CINQUO()
Dim s As Shape, Shp As Shape, i&, arrSh(100)
Set F = ActiveSheet: X = 300: Y = 20: L = 32: h = 10
'création et mise en forme du rectangle "modéle"
MEF_Shape F.Shapes.AddShape(1, 300, 20, 32, 10), "modele", vbRed, 189354
For i = 2 To F.Cells(Rows.Count, 1).End(xlUp).Row
rack = F.Cells(i, 1)
For j = 1 To Val(F.Cells(i, 2))
Set s = F.Shapes("modele").Duplicate
s.Left = X + L * (j - 1): s.Top = Y + (15 * (i - 2))
s.TextFrame.Characters.Text = rack & j: s.Name = rack & j
k = k + 1: arrSh(k) = s.Name
Next j
If j > 2 Then
F.Shapes.Range(arrSh).Group.Name = "Rangée_" & rack: Erase arrSh
End If
Next i
End Sub
Function MEF_Shape(s As Shape, Nom As String, Optional c_L As Long = vbBlue, Optional c_F As Long = vbWhite)
s.Name = Nom
With s.TextFrame.Characters.Font
.Size = 7: .Color = vbBlack
End With
s.TextFrame2.VerticalAnchor = 3: s.TextFrame2.TextRange.ParagraphFormat.Alignment = 2
s.Line.Weight = 1.5: s.Line.ForeColor.RGB = c_L: s.Fill.ForeColor.RGB = c_F
End Function
' On vide l'existant
For v = ActiveSheet.Shapes().Count To 1 Step -1
ActiveSheet.Shapes(v).Delete
Next v
'On vide l'existant
For v = ActiveSheet.Shapes.Count To 1 Step -1
ActiveSheet.Shapes(v).Delete
Next v
Sub MiseEnforme_Rack_Plan_G_SIXTO()
Dim s As Shape, Shp As Shape, i&, arrSh(100), col
raz
Set F = ActiveSheet: X = 300: Y = 20: L = 32: H = 10
col = Array(11851260, vbMagenta, 12566463, vbBlue, vbGreen, vbYellow, 9944516) 'tableau des couleurs
For i = 2 To F.Cells(Rows.Count, 1).End(xlUp).Row
rack = F.Cells(i, 1)
For j = 1 To Val(F.Cells(i, 2))
xCol = CLng(col(i - 2))
Set s = Forme(msoShapeRectangle, 300, 20, , , , xCol)
s.Left = X + L * (j - 1): s.Top = Y + (15 * (i - 2))
s.TextFrame.Characters.Text = rack & j: s.Name = rack & j
k = k + 1: arrSh(k) = s.Name
Next j
If j > 2 Then
F.Shapes.Range(arrSh).Group.Name = "Rangée_" & rack: Erase arrSh
End If
Next i
End Sub
Function Forme(atSh As MsoAutoShapeType, X, Y, Optional H = 32, Optional L = 10, Optional cLi = vbBlue, Optional cFi = vbWhite) As Shape
Set Forme = ActiveSheet.Shapes.AddShape(atSh, X, Y, H, L)
Forme.Line.Weight = 1.5: Forme.Line.ForeColor.RGB = cLi: Forme.Fill.ForeColor.RGB = cFi
Forme.TextFrame.Characters.Font.Size = 7: Forme.TextFrame.Characters.Font.Color = vbBlack
Forme.TextFrame2.VerticalAnchor = 3: Forme.TextFrame2.TextRange.ParagraphFormat.Alignment = 2
End Function
Sub raz()
Dim v& 'On vide l'existant
For v = ActiveSheet.Shapes.Count To 1 Step -1
ActiveSheet.Shapes(v).Delete
Next v
End Sub
Re
En attendant le fichier (et parce que l'aprés-midi est ici pluvieux et venteux)
Je me suis occupé dans mon VBA
J'attends tes questions et commentaires.
PS: Code à vocation purement illustrative
(on en fera l'usage que l'on veut ou pas)
Code:Sub MiseEnforme_Rack_Plan_G_SIXTO() Dim s As Shape, Shp As Shape, i&, arrSh(100), col raz Set F = ActiveSheet: X = 300: Y = 20: L = 32: H = 10 col = Array(11851260, vbMagenta, 12566463, vbBlue, vbGreen, vbYellow, 9944516) 'tableau des couleurs For i = 2 To F.Cells(Rows.Count, 1).End(xlUp).Row rack = F.Cells(i, 1) For j = 1 To Val(F.Cells(i, 2)) xCol = CLng(col(i - 2)) Set s = Forme(msoShapeRectangle, 300, 20, , , , xCol) s.Left = X + L * (j - 1): s.Top = Y + (15 * (i - 2)) s.TextFrame.Characters.Text = rack & j: s.Name = rack & j k = k + 1: arrSh(k) = s.Name Next j If j > 2 Then F.Shapes.Range(arrSh).Group.Name = "Rangée_" & rack: Erase arrSh End If Next i End Sub Function Forme(atSh As MsoAutoShapeType, X, Y, Optional H = 32, Optional L = 10, Optional cLi = vbBlue, Optional cFi = vbWhite) As Shape Set Forme = ActiveSheet.Shapes.AddShape(atSh, X, Y, H, L) Forme.Line.Weight = 1.5: Forme.Line.ForeColor.RGB = cLi: Forme.Fill.ForeColor.RGB = cFi Forme.TextFrame.Characters.Font.Size = 7: Forme.TextFrame.Characters.Font.Color = vbBlack Forme.TextFrame2.VerticalAnchor = 3: Forme.TextFrame2.TextRange.ParagraphFormat.Alignment = 2 End Function Sub raz() Dim v& 'On vide l'existant For v = ActiveSheet.Shapes.Count To 1 Step -1 ActiveSheet.Shapes(v).Delete Next v End Sub
Merci pour ton retour Job75. mais je veux colorier uniquement certaine travée de la rangée mais c'est une piste.Voyez ce fichier (3), les rangées à colorer sont listées dans le 2ème onglet.
Pas de soucis, c'est moi qui n'avais pas inséré le fichier.Bah j'avais cru comprendre qu'il fallait colorer les rangées.
öur xolorer les Sh
Mon message #41 s'était validé avant la fin par erreur, je l'ai complété.Donc ton code fonctionne très bien pour colorer une rangée
Re
@njm504
Je te laisse regarder le travail de job75 (message#37)
avant de remettre le nez dans mon VBE.
Mon fichier (4) colore comme vous avez demandé, testez-le.