Ajouter MsgBox après vérification remplissage des cellules
Bonjour,
J'ai appris à réaliser des Macros grâce à ce site.
Présentation de mon document :
Je travail sur un facturier, les clients sont listés et certains ont un numéro de facture, d'autres non (ça dépend des mois)
Lorsqu'ils ont un numéro de facture, plusieurs champs doivent être remplis pour éditer correctement la facture par publipostage.
J'ai créé une macro qui vérifie (en boucle avec "For i...") que, si le numéro de facture n'est pas vide et que le champ "prestation 1" est vide, alors j'ai une "InputBox" qui s'affiche pour remplir le champ en question.
Mon problème :
J'aimerai, une fois la vérification terminée, avoir une "MsgBox" qui me dise que tout est bien rempli.
Cependant, malgré tous mes essais, j'arrive sois :
- à avoir le MsgBox après chaque vérification (avec 169 client... Ca fait beaucoup de fois à cliquer sur "OK")
- à avoir le MsgBox dès que je quitte la boucle (solution que je garde pour le moment mais qui ne me convient pas car, lorsque mon "InputBox" s'affiche, si je ne rempli pas et que je clique sur "OK" ou "ANNULER" j'ai ma MsgBox qui s'affiche me disant que tout est bon...)
Ma Macro (Attention, c'est un peu long, mais en fait très répétitif.) Pour info, j'ai une macro pour chaque mois :
Sub Bouton_Facturier_Vérification_Juillet_Cliquer()
'
' Bouton_Facturier_Vérification_Juillet_Cliquer Macro
' Permet de faire remonter les champs non renseignés pour le mois de Juillet
'
For i = 2 To 180
'vérification Désignation Presta 1 :
If Cells(i, 21) <> "" And Cells(i, 33) = "" Then Cells(i, 33).Select
If Cells(i, 21) <> "" And Cells(i, 33) = "" Then Cells(i, 33) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("AG1"), "Mois de Juillet")
If Cells(i, 21) <> "" And Cells(i, 33) = "" Then Exit For
'vérification Heures Presta 1 :
If Cells(i, 21) <> "" And Cells(i, 45) = "" Then Cells(i, 45).Select
If Cells(i, 21) <> "" And Cells(i, 45) = "" Then Cells(i, 45) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("AS1"), "Mois de Juillet")
If Cells(i, 21) <> "" And Cells(i, 45) = "" Then Exit For
'vérification PU Presta 1 :
If Cells(i, 21) <> "" And Cells(i, 57) = "" Then Cells(i, 57).Select
If Cells(i, 21) <> "" And Cells(i, 57) = "" Then Cells(i, 57) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("BE1"), "Mois de Juillet")
If Cells(i, 21) <> "" And Cells(i, 57) = "" Then Exit For
'vérification Heures Presta 2 :
If Cells(i, 81) <> "" And Cells(i, 93) = "" Then Cells(i, 93).Select
If Cells(i, 81) <> "" And Cells(i, 93) = "" Then Cells(i, 93) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("CO1"), "Mois de Juillet")
If Cells(i, 81) <> "" And Cells(i, 93) = "" Then Exit For
'vérification PU Presta 2 :
If Cells(i, 81) <> "" And Cells(i, 105) = "" Then Cells(i, 105).Select
If Cells(i, 81) <> "" And Cells(i, 105) = "" Then Cells(i, 105) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("DA1"), "Mois de Juillet")
If Cells(i, 81) <> "" And Cells(i, 105) = "" Then Exit For
'vérification Heures Presta 3 :
If Cells(i, 129) <> "" And Cells(i, 141) = "" Then Cells(i, 141).Select
If Cells(i, 129) <> "" And Cells(i, 141) = "" Then Cells(i, 141) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("EK1"), "Mois de Juillet")
If Cells(i, 129) <> "" And Cells(i, 141) = "" Then Exit For
'vérification PU Presta 3 :
If Cells(i, 129) <> "" And Cells(i, 153) = "" Then Cells(i, 153).Select
If Cells(i, 129) <> "" And Cells(i, 153) = "" Then Cells(i, 153) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("EW1"), "Mois de Juillet")
If Cells(i, 129) <> "" And Cells(i, 153) = "" Then Exit For
'vérification TVA :
If Cells(i, 21) <> "" And Cells(i, 189) = "" Then Cells(i, 189).Select
If Cells(i, 21) <> "" And Cells(i, 189) = "" Then Cells(i, 189) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("GG1"), "Mois de Juillet")
If Cells(i, 21) <> "" And Cells(i, 189) = "" Then Exit For
'vérification PEC :
If Cells(i, 1) <> "Particulier" And Cells(i, 21) <> "" And Cells(i, 225) = "" Then Cells(i, 225).Select
If Cells(i, 1) <> "Particulier" And Cells(i, 21) <> "" And Cells(i, 225) = "" Then Cells(i, 225) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("HQ1"), "Mois de Juillet")
If Cells(i, 1) <> "Particulier" And Cells(i, 21) <> "" And Cells(i, 225) = "" Then Exit For
'vérification KM :
If Cells(i, 21) <> "" And Cells(i, 237) = "" Then Cells(i, 237).Select
If Cells(i, 21) <> "" And Cells(i, 237) = "" Then Cells(i, 237) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("IC1"), "Mois de Juillet")
If Cells(i, 21) <> "" And Cells(i, 237) = "" Then Exit For
Next
MsgBox ("Tous les champs sont bien remplis")
End SubMerci d'avoir lu jusqu'au bout.
Je joint un fichier qui vous aidera, j'espère, à comprendre.
Bonjour et bienvenue sur le forum
Essaie ce code :
Sub Bouton_Facturier_Vérification_Juillet_Cliquer()
'
' Bouton_Facturier_Vérification_Juillet_Cliquer Macro
' Permet de faire remonter les champs non renseignés pour le mois de Juillet
'
For i = 2 To 180
'vérification Désignation Presta 1 :
If Cells(i, 21) <> "" And Cells(i, 33) = "" Then
Cells(i, 33) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("AG1"), "Mois de Juillet")
'vérification Heures Presta 1 :
ElseIf Cells(i, 21) <> "" And Cells(i, 45) = "" Then
Cells(i, 45) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("AS1"), "Mois de Juillet")
'vérification PU Presta 1 :
ElseIf Cells(i, 21) <> "" And Cells(i, 57) = "" Then
Cells(i, 57) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("BE1"), "Mois de Juillet")
'vérification Heures Presta 2 :
ElseIf Cells(i, 81) <> "" And Cells(i, 93) = "" Then
Cells(i, 93) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("CO1"), "Mois de Juillet")
'vérification PU Presta 2 :
ElseIf Cells(i, 81) <> "" And Cells(i, 105) = "" Then
Cells(i, 105) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("DA1"), "Mois de Juillet")
'vérification Heures Presta 3 :
ElseIf Cells(i, 129) <> "" And Cells(i, 141) = "" Then
Cells(i, 141) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("EK1"), "Mois de Juillet")
'vérification PU Presta 3 :
ElseIf Cells(i, 129) <> "" And Cells(i, 153) = "" Then
Cells(i, 153) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("EW1"), "Mois de Juillet")
'vérification TVA :
ElseIf Cells(i, 21) <> "" And Cells(i, 189) = "" Then
Cells(i, 189) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("GG1"), "Mois de Juillet")
'vérification PEC :
ElseIf Cells(i, 1) <> "Particulier" And Cells(i, 21) <> "" And Cells(i, 225) = "" Then
Cells(i, 225) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("HQ1"), "Mois de Juillet")
'vérification KM :
ElseIf Cells(i, 21) <> "" And Cells(i, 237) = "" Then
Cells(i, 237) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("IC1"), "Mois de Juillet")
End If
Next
MsgBox ("Tous les champs sont bien remplis")
End SubBye !
Bonjour gmb, et merci pour ton aide.
Malheureusement, ce code ne résout pas mon problème...
1) Je tiens à garder mes "ExitFor" car ils me permettent de quitter la vérification à tout moment en cliquant sur Annuler quand une InputBox s'affiche. (Avec ton code, si je n'ai rien rempli, je dois cliquer sur annuler 180 fois pour arriver à la fin de la macro)
2) En mettant des ElseIf au lieu des If, la vérification ne se fait plus partout
For i = 2 To 180
'vérification Désignation Presta 1 :
If Cells(i, 21) <> "" And Cells(i, 33) = "" Then
Cells(i, 33) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("AG1"), "Mois de Juillet")
'vérification Heures Presta 1 :
ElseIf Cells(i, 21) <> "" And Cells(i, 45) = "" Then
Cells(i, 45) = InputBox("Remplir pour :" & Chr(10) & Chr(10) & Cells(i, 3) & " " & Cells(i, 4) & Chr(10) & Chr(10) & Range("AS1"), "Mois de Juillet")Avec ce code, si la cellule i,33 est vide, alors la vérification s'arrête pour la ligne i (elle ne se lance pas pour la cellule i,45) et elle reprend à la ligne i+1.
J'explique mon problème différemment :
Ma macro est bonne, elle s'exécute correctement et vérifie bien toutes les cellules.
Le seul petit problème que je n'arrive pas à résoudre est que, quand une inputbox s'affiche et que je clique sur Annuler, j'ai la Msgbox qui s'affiche (tous les champs sont bien remplis). Or je voudrais qu'elle ne s'affiche qu'une seule fois et uniquement lorsque tous les champs sont vérifiés.
Il me faudrait un code du genre :
If Cells(i, 21) <> "" And Cells(i, 33) <> "" Then MsgBox ("Tous les champs sont bien remplis")Mais dans ce cas, le message s'affiche 180 fois... et je voudrais qu'il ne s'affiche qu'une fois que la ligne 180 ait été vérifiée.
Peut être est-il possible de créer une boucle :
If Cells(i, 21) <> "" And Cells(i, 33) <> "" Then
[vérifier la ligne suivante]
[une fois la ligne 180 vérifiée] MsgBox ("Tous les champs sont bien remplis")Voila, bon courage, encore merci pour le temps que tu y a passé et désolé si je suis long à répondre, mais je n'ai Excel qu'au bureau.