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 !

YannC.

XLDnaute Occasionnel
Bonjour à vous tous,

J'aimerai savoir si il est possible de reduire cette partie de code :
With PTextBox7
.Value = ""
.Enabled = False
End With
With PTextBox8
.Value = ""
.Enabled = False
End With
With PTextBox9
.Value = ""
.Enabled = False
End With
With PTextBox10
.Value = ""
.Enabled = False
End With
With PTextBox11
.Value = ""
.Enabled = False
End With
With PTextBox12
.Value = ""
.Enabled = False
End With
With PTextBox13
.Value = ""
.Enabled = False
End With
With PTextBox14
.Value = ""
.Enabled = False
End With
With PTextBox15
.Value = ""
.Enabled = False
End With
With PTextBox16
.Value = ""
.Enabled = False
End With
With PTextBox17
.Value = ""
.Enabled = False
End With
With PTextBox18
.Value = ""
.Enabled = False
End With
With PTextBox19
.Value = ""
.Enabled = False
End With
With PTextBox20
.Value = ""
.Enabled = False
End With
With PTextBox21
.Value = ""
.Enabled = False
End With
With PTextBox21
.Value = ""
.Enabled = False
End With
With PTextBox22
.Value = ""
.Enabled = False
End With
With PTextBox23
.Value = ""
.Enabled = False
End With
With PTextBox24
.Value = ""
.Enabled = False
End With
With PTextBox25
.Value = ""
.Enabled = False
End With
With PTextBox26
.Value = ""
.Enabled = False
End With
With PTextBox27
.Value = ""
.Enabled = False
End With
With PTextBox28
.Value = ""
.Enabled = False
End With
With PTextBox29
.Value = ""
.Enabled = False
End With
With PTextBox30
.Value = ""
.Enabled = False
End With
With PTextBox31
.Value = ""
.Enabled = False
End With
With PTextBox32
.Value = ""
.Enabled = False
End With
With PTextBox33
.Value = ""
.Enabled = False
End With
With PTextBox34
.Value = ""
.Enabled = False
End With
With PTextBox35
.Value = ""
.Enabled = False
End With
With PTextBox36
.Value = ""
.Enabled = False
End With
With PTextBox37
.Value = ""
.Enabled = False
End With
With PTextBox38
.Value = ""
.Enabled = False
End With
With PTextBox39
.Value = ""
.Enabled = False
End With
With PTextBox40
.Value = ""
.Enabled = False
End With
With PTextBox41
.Value = ""
.Enabled = False
End With
With PTextBox42
.Value = ""
.Enabled = False
End With
With PTextBox43
.Value = ""
.Enabled = False
End With
With PTextBox44
.Value = ""
.Enabled = False
End With
With PTextBox45
.Value = ""
.Enabled = False
End With
With PTextBox46
.Value = ""
.Enabled = False
End With
With PTextBox47
.Value = ""
.Enabled = False
End With
With PTextBox48
.Value = ""
.Enabled = False
End With
With PTextBox49
.Value = ""
.Enabled = False
End With
With PTextBox50
.Value = ""
.Enabled = False
End With
With PTextBox51
.Value = ""
.Enabled = False
End With
With PTextBox52
.Value = ""
.Enabled = False
End With
With PTextBox53
.Value = ""
.Enabled = False
End With
With PTextBox54
.Value = ""
.Enabled = False
End With
With PTextBox55
.Value = ""
.Enabled = False
End With
With PTextBox56
.Value = ""
.Enabled = False
End With
With PTextBox57
.Value = ""
.Enabled = False
End With
With PTextBox58
.Value = ""
.Enabled = False
End With
With PTextBox59
.Value = ""
.Enabled = False
End With
With PTextBox60
.Value = ""
.Enabled = False
End With
With PTextBox61
.Value = ""
.Enabled = False
End With
With PTextBox62
.Value = ""
.Enabled = False
End With
With PTextBox63
.Value = ""
.Enabled = False
End With
With PTextBox64
.Value = ""
.Enabled = False
End With
With PTextBox65
.Value = ""
.Enabled = False
End With
With PTextBox66
.Value = ""
.Enabled = False
End With
With PTextBox67
.Value = ""
.Enabled = False
End With
With PTextBox68
.Value = ""
.Enabled = False
End With
With PTextBox69
.Value = ""
.Enabled = False
End With

Et si oui Comment ?

Merci de votre aide

Le Linuxien
 
Re : Reduction de code

Bonsoir lelinuxien

regarde le code ci-dessous, boucle sur tous les textbox présents sur ton usf. Si cela peut t'aider...

Code:
Dim Ctrl As Control
For Each Ctrl In Me.Controls
    If TypeOf Ctrl Is MSForms.TextBox Then
        Ctrl.Enabled = False
        Ctrl.Value = ""
    End If
Next Ctrl

A utiliser dans le module de ton USF, en espérant qu'ils sont bien dessus...

bonne soirée
@+
 
Re : Reduction de code

Bonsoir le linuxien,

Avec un truc du genre :

For i=7 to 69

PTextBox(i)
.Value = ""
.Enabled = False
next i

Même pas réfléchis à la faisabilité. Du direct quoi...

Bonne soirée.

Jean-Pierre

Edit : Salut Pierrot, plus pro, évidemment
 
Re : Reduction de code

Re, bonsoir Jean-Pierre

Aarf Jean-Pierre🙂, ton code devrait fonctionner, modifié comme suit :

Code:
For i = 7 To 69
    With Controls("PTextBox" & i)
        .Value = ""
        .Enabled = False
    End With
Next i

te souhaitant une bonne soirée.
@+
 
Re : Reduction de code

Merci pour vos code Pierrot93 & Jean Pierre,

Effectivement mon code se trouve dans un userform placer dans le initialyse...
Et comme j'ai plusieurs autre textebox, le code de Pierrot93 me pose probleme, mais je pense l'idée bonne. Il faut que j'arrive à lui indiquer seulement les textboxs de 7 à 69.

Pour le code de Jean Pierre, il me marque
Sub ou function non défini
en s'arretant sur ptextbox(i). Pourquoi je ne sais pas.

Voilà les nouvelles, et si vous pouvez encore m'aider ce serait avec joie.

@+

Le linuxien
 
Re : Reduction de code

Re, bonsoir Jean-Pierre

Aarf Jean-Pierre🙂, ton code devrait fonctionner, modifié comme suit :

Code:
For i = 7 To 69
    With Controls("PTextBox" & i)
        .Value = ""
        .Enabled = False
    End With
Next i

te souhaitant une bonne soirée.
@+

Effectivement Pierrot93, cela fonctionne parfaitement comme tu l'as dit.

Merci beaucoup à tous les deux pour votre aide

Bonne soirée

Le linuxien
 
- 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
10
Affichages
678
Réponses
5
Affichages
927
Réponses
9
Affichages
390
  • Question Question
XL 2021 listbox
Réponses
18
Affichages
764
Réponses
4
Affichages
742
Retour