Raccourcir procédure

Résolu/Fermé
greg.18 Messages postés 5 Date d'inscription jeudi 31 octobre 2013 Statut Membre Dernière intervention 31 octobre 2013 - 31 oct. 2013 à 12:21
Gyrus Messages postés 3334 Date d'inscription samedi 20 juillet 2013 Statut Membre Dernière intervention 9 décembre 2016 - 31 oct. 2013 à 20:17
Bonjour à tous,

je souhaiterais si possible raccourcir la procédure suivante (je dois la répéter 12 fois):

Private Sub CommandButton1_saisie_Click()
If mois1.Value = True Then
Sheets("SAISIE M PLF232").Activate
If TextBox1 = "" Then
TextBox1 = Range("c2")
Else
Range("C2") = TextBox1
End If
If TextBox2 = "" Then
TextBox2 = Range("c3")
Else
Range("C3") = TextBox2
End If
If TextBox3 = "" Then
TextBox3 = Range("c4")
Else
Range("C4") = TextBox3
End If
If TextBox4 = "" Then
TextBox4 = Range("c5")
Else
Range("C5") = TextBox4
End If
If TextBox5 = "" Then
TextBox5 = Range("c6")
Else
Range("C6") = TextBox5
End If
If TextBox6 = "" Then
TextBox6 = Range("c7")
Else
Range("C7") = TextBox6
End If
If TextBox7 = "" Then
TextBox7 = Range("c8")
Else
Range("C8") = TextBox7
End If
If TextBox8 = "" Then
TextBox8 = Range("c9")
Else
Range("C9") = TextBox8
End If
If TextBox9 = "" Then
TextBox9 = Range("c10")
Else
Range("C10") = TextBox9
End If
If TextBox10 = "" Then
TextBox10 = Range("c11")
Else
Range("C11") = TextBox10
End If
If TextBox11 = "" Then
TextBox11 = Range("c12")
Else
Range("C12") = TextBox11
End If
If TextBox12 = "" Then
TextBox12 = Range("c13")
Else
Range("C13") = TextBox12
End If
If TextBox13 = "" Then
TextBox13 = Range("c14")
Else
Range("C14") = TextBox13
End If
If TextBox14 = "" Then
TextBox14 = Range("c15")
Else
Range("C15") = TextBox14
End If
If TextBox15 = "" Then
TextBox15 = Range("c16")
Else
Range("C16") = TextBox15
End If
If TextBox16 = "" Then
TextBox16 = Range("c17")
Else
Range("C17") = TextBox16
End If
If TextBox17 = "" Then
TextBox17 = Range("c18")
Else
Range("C18") = TextBox17
End If
If TextBox18 = "" Then
TextBox18 = Range("c19")
Else
Range("C19") = TextBox18
End If
If TextBox19 = "" Then
TextBox19 = Range("c20")
Else
Range("C20") = TextBox19
End If
If TextBox20 = "" Then
TextBox20 = Range("c21")
Else
Range("C21") = TextBox20
End If
If TextBox21 = "" Then
TextBox21 = Range("c22")
Else
Range("C22") = TextBox21
End If
If TextBox22 = "" Then
TextBox22 = Range("c23")
Else
Range("C23") = TextBox22
End If
If TextBox23 = "" Then
TextBox23 = Range("c24")
Else
Range("C24") = TextBox23
End If
If TextBox24 = "" Then
TextBox24 = Range("c25")
Else
Range("C25") = TextBox24
End If
If TextBox25 = "" Then
TextBox25 = Range("c26")
Else
Range("C26") = TextBox25
End If
If TextBox26 = "" Then
TextBox26 = Range("c27")
Else
Range("C27") = TextBox26
End If
If TextBox27 = "" Then
TextBox27 = Range("c28")
Else
Range("C28") = TextBox27
End If
If TextBox28 = "" Then
TextBox28 = Range("c29")
Else
Range("C29") = TextBox28
End If
If TextBox29 = "" Then
TextBox29 = Range("c30")
Else
Range("C30") = TextBox29
End If
Unload Me

N'hésitez pas à me signaler si j'ai fait une boulette (règle du forum ou post, etc...)

Vous remerciant par avance.

Greg

7 réponses

Gyrus Messages postés 3334 Date d'inscription samedi 20 juillet 2013 Statut Membre Dernière intervention 9 décembre 2016 523
31 oct. 2013 à 13:21
Bonjour,

Je n'ai pas bien compris l'intérêt de renseigner la TextBox avec la valeur de la colonne C dans le cas où la TextBox est vide puisque tu supprimes le Userform de la mémoire en fin de procédure avec Unload.

Private Sub CommandButton1_saisie_Click()
Dim i As Integer
If mois1.Value = True Then Sheets("SAISIE M PLF232").Activate
For i = 1 To 29
If Controls("TextBox" & i).Value = "" Then
Controls("TextBox" & i).Value = Cells(i + 1, 3).Value
Else
Cells(i + 1, 3).Value = Controls("TextBox" & i).Value
End If
Next i
Unload Me
End Sub

A+
1
greg.18 Messages postés 5 Date d'inscription jeudi 31 octobre 2013 Statut Membre Dernière intervention 31 octobre 2013
31 oct. 2013 à 15:53
Merci pour la réponse rapide!

En fait si je souhaite renseigner la TextBox avec la valeur de la colonne c'est au cas ou l'une des donnée qui est renseignée dans celle-ci évolue et que je veux la modifier je n'ai qu'à la saisir et valider sans avoir à saisir tout le reste ou que tout sois supprimé.
je ne sais pas trop si j'ai été très clair...

Et je suis désolé (je débute) mais je n'arrive pas à dupliquer pour les 11 autres mois...

Merci d'avance.
0
Gyrus Messages postés 3334 Date d'inscription samedi 20 juillet 2013 Statut Membre Dernière intervention 9 décembre 2016 523
31 oct. 2013 à 16:20
Le problème c'est que tu ne donnes aucune indication sur la structure de ta feuille et de ton Userform. Ton code indique simplement que tu remplis 29 cellules de la colonne C de la feuille "SAISIE M PLF232" avec les valeurs de 29 TextBox suivant autorisation donnée à priori par une CheckBox nommée mois1.

Pour aller plus loin, il faudrait joindre un classeur exemple et quelques explications.


A+
0
greg.18 Messages postés 5 Date d'inscription jeudi 31 octobre 2013 Statut Membre Dernière intervention 31 octobre 2013
31 oct. 2013 à 17:09
Merci encore,

en fait c'est ce que je voulais faire au début mais je dois être mauvais, je ne sais pas comment faire...
0
Gyrus Messages postés 3334 Date d'inscription samedi 20 juillet 2013 Statut Membre Dernière intervention 9 décembre 2016 523
31 oct. 2013 à 18:03
Tu n'es pas le premier à te poser la question.
Voici un lien pour t'aider
https://www.commentcamarche.net/faq/29493-utiliser-cjoint-pour-heberger-des-fichiers#q=cjoint&cur=1&url=%2F

A+
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
greg.18 Messages postés 5 Date d'inscription jeudi 31 octobre 2013 Statut Membre Dernière intervention 31 octobre 2013
31 oct. 2013 à 18:17
j'ai eu une autre idée (mais je ne sais pas si c'est une bonne idée)

https://forum.excel-pratique.com/download/file.php?id=54065
0
Gyrus Messages postés 3334 Date d'inscription samedi 20 juillet 2013 Statut Membre Dernière intervention 9 décembre 2016 523
31 oct. 2013 à 19:28
Tu peux commencer comme cela
https://www.cjoint.com/?CJFtBtQg79p

A+
0
greg.18 Messages postés 5 Date d'inscription jeudi 31 octobre 2013 Statut Membre Dernière intervention 31 octobre 2013
31 oct. 2013 à 19:45
génial!!!

maintenant si tu me permet je vais être un peu "chiant"...

tu veux bien m'expliquer STP?

merci d'avance
0
Gyrus Messages postés 3334 Date d'inscription samedi 20 juillet 2013 Statut Membre Dernière intervention 9 décembre 2016 523
31 oct. 2013 à 20:17
Je veux bien mais encore faut-il que tu dises ce que tu ne comprends pas.

A+
0