Microsoft 365 Format date en boucle sur les labels

labellebleu

XLDnaute Nouveau
Bonjour à tous,
je me décide a vous demandé de l'aide, ça fait longtemps que je cherche en vain.
je cherche a faire une boucle avec ce qui suit:
VB:
 Label1 = Format(Label1, "ddd dd")
    Label2 = Format(Label2, "ddd dd")
    Label3 = Format(Label3, "ddd dd")
    Label4 = Format(Label4, "ddd dd")
    Label5 = Format(Label5, "ddd dd")
    Label6 = Format(Label6, "ddd dd")
    Label7 = Format(Label7, "ddd dd")
    Label8 = Format(Label8, "ddd dd")
    Label9 = Format(Label9, "ddd dd")
    Label10 = Format(Label10, "ddd dd")
    Label11 = Format(Label11, "ddd dd")
    Label12 = Format(Label12, "ddd dd")
    Label13 = Format(Label13, "ddd dd")
    Label14 = Format(Label14, "ddd dd")
    Label15 = Format(Label15, "ddd dd")

en boucle.
D'avance un grand merci de votre aide.
 
Solution
Bonsoir

Ce petit test, cela semble fonctionner
(Pour tester un userform avec 4 labels et un commandbutton)
VB:
Private Sub CommandButton1_Click()
Dim ctr As MSForms.Control
For Each ctr In Me.Controls
If TypeOf ctr Is MSForms.Label Then
ctr.Caption = Format(ctr.Caption, "ddd dd")
End If
Next
End Sub
Private Sub UserForm_Initialize()
Label1.Caption = Date
Label2.Caption = Date + 10
Label3.Caption = Date + 20
Label4.Caption = Date + 30
End Sub

Dranreb

XLDnaute Barbatruc
Bonsoir.
Ce format "ddd dd" ne peut s'appliquer qu'à une Date, non un String, à moins qu'il puisse être converti en Date. S'il ne comporte pas tous les éléments d'une date (jour, mois et an) il faut les apporter et en constituer une Date.
Par exemple :
VB:
 Label1.Caption = Format(DateSerial(Year(Date), Month(Date), Right$(Label1.Caption, 2)), "ddd dd")
 
Dernière édition:

Staple1600

XLDnaute Barbatruc
Bonsoir

Ce petit test, cela semble fonctionner
(Pour tester un userform avec 4 labels et un commandbutton)
VB:
Private Sub CommandButton1_Click()
Dim ctr As MSForms.Control
For Each ctr In Me.Controls
If TypeOf ctr Is MSForms.Label Then
ctr.Caption = Format(ctr.Caption, "ddd dd")
End If
Next
End Sub
Private Sub UserForm_Initialize()
Label1.Caption = Date
Label2.Caption = Date + 10
Label3.Caption = Date + 20
Label4.Caption = Date + 30
End Sub
 

Statistiques des forums

Discussions
312 215
Messages
2 086 329
Membres
103 184
dernier inscrit
Di Martino