Macro en Excel

Résolu
Boschmanspi Messages postés 73 Date d'inscription   Statut Membre Dernière intervention   -  
Boschmanspi Messages postés 73 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

Merci d'avance pour votre réponse.
Cette routine (partie de macro) en excel devrait pouvoir initiiler les labels si .Labl1 pouvait devenir .Label2, Label3 .... suivant I. Est-ce possible ?

' For I = 1 To 10
' .Label1.Caption = Worksheets("Data").Cells(1, I)
' Next I


2 réponses

f894009 Messages postés 17277 Date d'inscription   Statut Membre Dernière intervention   1 715
 
Bonjour,

'contrôles dans une feuille de calcul
Private Sub CommandButton1_Click()
Dim Obj As OLEObject
'boucle sur la Feuil1
For Each Obj In Sheets("Feuil1").OLEObjects
'verifie s'il s'agit d'un Label
If TypeOf Obj.Object Is MSForms.Label Then
I = CInt(Mid(Obj.Name, 6, 2))
Obj.Object.Caption = Worksheets("Data").Cells(1, I)
End If
Next Obj
End Sub

'contrôles dans UserForm
Private Sub CommandButton2_Click()
Dim Cont As Control
'Boucle sur UF
For Each Cont In Me.Controls
'verifie s'il s'agit d'un Label
If TypeOf Cont Is MSForms.Label Then
I = CInt(Mid(Cont.Name, 6, 2))
Cont.Object.Caption = Worksheets("Data").Cells(1, I)
End If
Next Cont
End Sub

'ou
'contrôles dans UserForm
Private Sub CommandButton3_Click()
For I = 1 To 30
Me("Label" & I).Caption = Worksheets("Data").Cells(1, I)
Next I
End If

Bonne suite
0
Boschmanspi Messages postés 73 Date d'inscription   Statut Membre Dernière intervention   2
 
Cher ami,
merci pour vos informations. mon problèe est maintenant résolu Grace à l'instruuction (Me(".....) Encore merci
Pierre
0