Microsoft 365 Format date en boucle sur les labels

  • Initiateur de la discussion Initiateur de la discussion labellebleu
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

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
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:
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
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
2
Affichages
945
Réponses
7
Affichages
829
Réponses
2
Affichages
6 K
Réponses
7
Affichages
827
Retour