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 MiseEnformerack_Plan_G()
'variable
Dim sh As Shape, r, NbRangee&, nbtravee&, Coorx&, Coory&, n&, ligne&
Dim tab_SHP() As Variant, v&, shp As Shape
n = 0
NbRangee = Feuil6.Range("C2").Value 'nb derangée
' On vide l'existant
For i = ActiveSheet.Shapes().Count To 1 Step -1
ActiveSheet.Shapes(i).Delete
Next i
' Valeurs de départ
Coorx = 300: Coory = 20
'Boucle des rangées
For nbligne = 1 To NbRangee
ligne = nbligne + 1
nbtravee = Cells(ligne, 2).Value
n = n + 1
'Boucle des travées
For t = 1 To nbtravee
With ActiveSheet.Shapes().AddShape(msoShapeRectangle, Coorx, Coory, 32, 10)
nom = Cells(ligne, 1) & t
.Line.Weight = 1.5
.Line.ForeColor.RGB = RGB(30, 144, 255)
.Fill.ForeColor.RGB = RGB(255, 255, 255)
.Name = nom
With .TextFrame.Characters
.Font.Size = 7: .Font.Color = vbBlack: .Text = nom
End With
.TextFrame2.VerticalAnchor = msoAnchorMiddle
.TextFrame2.TextRange.ParagraphFormat.Alignment = msoAlignCenter
End With
' Position suivante
Coorx = Coorx + 32
If t = nbtravee Then
Coorx = 300
Coory = Coory + 15
End If
Next t
Next nbligne
' Grouper les Shapes par rangée
With ActiveSheet
ReDim tab_SHP(1 To .Shapes.Count)
For v = 1 To .Shapes.Count
If .Shapes(v).AutoShapeType = 1 Then ' 1=Rectangle
tab_SHP(v) = .Shapes(v).Name
End If
Next v
ActiveSheet.Shapes.Range(tab_SHP).Group.Name = "PLAN_G"
End With
MsgBox "Le plan général a été crée !"
End Sub
Sub MiseEnformerack_Plan_G_B()
'variable
Dim sh As Shape, r, NbRangee&, nbtravee&, Coorx&, Coory&, n&, ligne&, arrSh()
Dim tab_SHP() As Variant, v&, shp As Shape
n = 0
NbRangee = Feuil6.Range("C2").Value 'nb derangée
' On vide l'existant
For i = ActiveSheet.Shapes().Count To 1 Step -1
ActiveSheet.Shapes(i).Delete
Next i
' Valeurs de départ
Coorx = 300: Coory = 20
'Boucle des rangées
For nbligne = 1 To NbRangee
ligne = nbligne + 1
nbtravee = Cells(ligne, 2).Value
n = n + 1
'Boucle des travées
ReDim arrSh(nbtravee)
For t = 1 To nbtravee
With ActiveSheet.Shapes().AddShape(msoShapeRectangle, Coorx, Coory, 32, 10)
nom = Cells(ligne, 1) & t
.Line.Weight = 1.5
.Line.ForeColor.RGB = RGB(30, 144, 255)
.Fill.ForeColor.RGB = RGB(255, 255, 255)
.Name = nom
With .TextFrame.Characters
.Font.Size = 7: .Font.Color = vbBlack: .Text = nom
End With
.TextFrame2.VerticalAnchor = msoAnchorMiddle
.TextFrame2.TextRange.ParagraphFormat.Alignment = msoAlignCenter
arrSh(t) = .Name
End With
' Position suivante
Coorx = Coorx + 32
If t = nbtravee Then
ActiveSheet.Shapes.Range(arrSh).Group.Name = "Rangée_" & Cells(ligne, 1).Value
Erase arrSh
Coorx = 300
Coory = Coory + 15
End If
Next t
Next nbligne
MsgBox "Le plan général a été crée !"
End Sub
Quand on voit les userforms qu'il y a dans ton classeur, je n'appelle pas cela "débuter dans la carrière" en VBATu à dit:Voici mon code (attention je suis débutant!), tu y trouveras ton code n°2.
Sub MiseEnforme_Rack_Plan_G_TER()
Dim s As Shape, Shp As Shape, i&, arrSh(100)
Set f = ActiveSheet: X = 300: Y = 20
With f.Shapes.AddShape(1, 300, 20, 32, 10) 'c'est le rectangle "modéle" avec définition des ses propriétés
With .TextFrame.Characters: .Font.Size = 7: .Font.Color = vbBlack: End With: .Name = "modele"
.Line.Weight = 1.5: .TextFrame2.VerticalAnchor = 3: .TextFrame2.TextRange.ParagraphFormat.Alignment = 2
.Line.ForeColor.RGB = RGB(30, 144, 255): .Fill.ForeColor.RGB = RGB(255, 255, 255)
End With
For i = 2 To f.Cells(Rows.Count, 1).End(xlUp).Row
For j = 1 To Cells(i, 2).Value
Set Shp = f.Shapes("modele").Duplicate 'duplication N fois du modéle
With Shp
nom = Cells(i, 1) & j: .Left = X + XX: .Top = Y + YY: .Name = nom
.TextFrame.Characters.Text = nom: k = k + 1: arrSh(k) = .Name
End With
XX = XX + 32
If j = Cells(i, 2).Value Then
f.Shapes.Range(arrSh).Group.Name = "Rangée_" & Cells(i, 1).Value 'groupage des formes
Erase arrSh: YY = (YY + 15)
End If
Next
Next
'un peu de ménage
f.Shapes("modele").Delete: For Each s In ActiveSheet.Shapes: s.Left = 300: Next
End Sub
f.Shapes.Range(arrSh).Group.Name = "Rangée_" & Cells(i, 1).Value 'groupage des formes
Sub Creer_Shapes()
Dim F As Worksheet, model As Shape, L, h, debx, deby, s, i&, lettre$, j%
Set F = Feuil6
Set model = F.Shapes("Modele")
L = model.Width
h = model.Height
debx = 300
deby = 20
Application.ScreenUpdating = False
'---RAZ---
For Each s In F.Shapes
If s.Name Like "Groupe*" Then s.Delete
Next
'---duplication et groupage---
For i = 2 To F.[A1].CurrentRegion.Rows.Count
lettre = F.Cells(i, 1)
For j = 1 To Val(F.Cells(i, 2))
Set s = model.Duplicate
s.Left = debx + L * (j - 1)
s.Top = deby + (h + 15) * (i - 2)
s.TextFrame.Characters.Text = lettre & j
s.Name = lettre & j
s.Select False 'sélection multiple
Next j
If j > 2 Then
Set s = Selection.Group
s.Name = "Groupe " & lettre
ActiveCell.Activate 'désélectionne
End If
Next i
End Sub
Sub MiseEnforme_Rack_Plan_G_QUATRO()
Dim s As Shape, Shp As Shape, i&, arrSh(100)
Set f = ActiveSheet: X = 300: Y = 20
'création et mise en forme du rectangle "modéle"
MEF_Shape f.Shapes.AddShape(1, 300, 20, 32, 10), "modele"
For i = 2 To f.Cells(Rows.Count, 1).End(xlUp).Row
For j = 1 To Cells(i, 2).Value
Set Shp = f.Shapes("modele").Duplicate 'duplication N fois du modéle
With Shp
Nom = Cells(i, 1) & j: .Left = X + XX: .Top = Y + YY: .Name = Nom
.TextFrame.Characters.Text = Nom: k = k + 1: arrSh(k) = .Name
End With
XX = XX + 32
If j = Cells(i, 2).Value Then
f.Shapes.Range(arrSh).Group.Name = "Rangée_" & Cells(i, 1).Value 'groupage des formes
Erase arrSh: YY = (YY + 15)
End If
Next
Next
'un peu de ménage
f.Shapes("modele").Delete: For Each s In ActiveSheet.Shapes: s.Left = 300: Next
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