Bonjour,

je bloque sur une macro et je ne trouve pas de réponse sur les différents forum
je souhaite coder une macro qui me colle des optionbutton sur une ligne en fonction du remplissage de la première cellule de la ligne
pour le moment, j'ai codé le fait de copier/coller des optionbutton

lorsque je lance ma macro une fois, pas de problème
par contre, lorsque je relance ma macro, j'ai le message d'erreur suivant que je ne comprend pas :

"Erreur de compilation!
Bibliothèque d'objet incorrecte ou contenant des références à des définitions d'objets introuvables"


d'avance merci pour votre aide


ci dessous mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
Public j As Long
 
Public Sub ajout_OptionButton()
 
Static i As Integer
'Static j As Integer
Static k As Integer
'For j = 4 To 5          'ligne 4 et 5
'j = 4
For i = 1 To 2          'optionbutton1 et optionbutton2
'ActiveSheet.Shapes("OptionButton" & i).Select
Sheets("test").Shapes("OptionButton" & i).Select
    Selection.Copy
    Cells(j + 4, i + 3).Select 'i + 3 car optionbutton1 en colonne 4, optionbutton en colone 5
'    ActiveSheet.Paste
'    Set shp = ActiveSheet.Shapes(Selection.Name)
    Sheets("test").Paste
    Set shp = Sheets("test").Shapes(Selection.Name)
    With shp.OLEFormat.Object
        .Object.Caption = "pre_" & k + 1
        .Name = "pre_" & k + 1
        .Object.GroupName = "pre_" & k + 1
    End With
 
Next
For i = 3 To 4
'ActiveSheet.Shapes("OptionButton" & i).Select
Sheets("test").Shapes("OptionButton" & i).Select
    Selection.Copy
    Cells(j + 4, i + 3).Select
    'ActiveSheet.Paste
    'Set shp = ActiveSheet.Shapes(Selection.Name)
    Sheets("test").Paste
    Set shp = Sheets("test").Shapes(Selection.Name)
    With shp.OLEFormat.Object
        .Object.Caption = "lis_" & k + 1
        .Name = "lis_" & k + 1
        .Object.GroupName = "lis_" & k + 1
    End With
Next
 
For i = 5 To 6
'ActiveSheet.Shapes("OptionButton" & i).Select
Sheets("test").Shapes("OptionButton" & i).Select
    Selection.Copy
    Cells(j + 4, i + 4).Select
'    ActiveSheet.Paste
'    Set shp = ActiveSheet.Shapes(Selection.Name)
    Sheets("test").Paste
    Set shp = Sheets("test").Shapes(Selection.Name)
    With shp.OLEFormat.Object
        .Object.Caption = "pat_" & k + 1
        .Name = "pat_" & k + 1
        .Object.GroupName = "pat_" & k + 1
    End With
Next
 
For i = 7 To 8
'ActiveSheet.Shapes("OptionButton" & i).Select
Sheets("test").Shapes("OptionButton" & i).Select
    Selection.Copy
    Cells(j + 4, i + 5).Select
    'ActiveSheet.Paste
    Sheets("test").Paste
    'Set shp = ActiveSheet.Shapes(Selection.Name)
    Set shp = Sheets("test").Shapes(Selection.Name)
    With shp.OLEFormat.Object
        .Object.Caption = "tem_" & k + 1
        .Name = "tem_" & k + 1
        .Object.GroupName = "tem_" & k + 1
    End With
Next
 
For i = 9 To 10
'ActiveSheet.Shapes("OptionButton" & i).Select
Sheets("test").Shapes("OptionButton" & i).Select
    Selection.Copy
    Cells(j + 4, i + 6).Select
    Sheets("test").Paste
    'ActiveSheet.Paste
    'Set shp = ActiveSheet.Shapes(Selection.Name)
    Set shp = Sheets("test").Shapes(Selection.Name)
    With shp.OLEFormat.Object
        .Object.Caption = "med_" & k + 1
        .Name = "med_" & k + 1
        .Object.GroupName = "med_" & k + 1
    End With
Next
 
For i = 11 To 12
'ActiveSheet.Shapes("OptionButton" & i).Select
Sheets("test").Shapes("OptionButton" & i).Select
    Selection.Copy
    Cells(j + 4, i + 6).Select
    'ActiveSheet.Paste
    Sheets("test").Paste
    'Set shp = ActiveSheet.Shapes(Selection.Name)
    Set shp = Sheets("test").Shapes(Selection.Name)
    With shp.OLEFormat.Object
        .Object.Caption = "con_" & k + 1
        .Name = "con_" & k + 1
        .Object.GroupName = "con_" & k + 1
    End With
Next
 
For i = 13 To 15
'ActiveSheet.Shapes("OptionButton" & i).Select
Sheets("test").Shapes("OptionButton" & i).Select
    Selection.Copy
    Cells(j + 4, i + 6).Select
    'ActiveSheet.Paste
    Sheets("test").Paste
'    Set shp = ActiveSheet.Shapes(Selection.Name)
    Set shp = Sheets("test").Shapes(Selection.Name)
    With shp.OLEFormat.Object
        .Object.Caption = "cor_" & k + 1
        .Name = "cor_" & k + 1
        .Object.GroupName = "cor_" & k + 1
    End With
Next
 
k = j - 3   'à la première boucle k = 1
'MsgBox j
'MsgBox k
'Next
j = j + 1
MsgBox j
End Sub