Grouper textes de plusieurs MsgBox

Chonbie Messages postés 183 Statut Membre -  
pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   -
Bonjour,

J'ai réaliser un module qui me permet de localiser dans un tableau les cellules contenant un certain texte et de me renvoyer des informations concernant ces cellules dans des MsgBox. Le truc c'est que pour chaque cellule, il m'ouvre une MsgBox que je valide, puis une autre que je valide, puis une autre... Puis-je lui demander de stocker les informations pour qu'il ne me sorte qu'une MsgBox rassemblant toutes les cellules trouvées?

Voici mon code:
Sub a_commander() 
' 
' a_commander Macro 
' 
' Touche de raccourci du clavier: Ctrl+o 
' 

'définition des variables 
Dim texte As Variant 
Dim cas As String 
Dim ligne As Integer 
Dim col As Integer 
Dim chant As Long 

'le texte à chercher 
texte = "AC" 

'page et plage 
With Worksheets(1).Range("A1:BE10000") 

'fonction 
Set cas = .Find(texte, lookat:=xlPart, searchorder:=xlByColumns) 

If Not cas Is Nothing Then 
termine = cas.Address 

Do 
ligne = cas.Row 
col = cas.Column - 5 
nom = Range("D" & ligne).Formula 
chant = Range("B" & ligne).End(xlUp).Row 
chantier = Range("B" & chant).Formula 

'Message Box 
MsgBox "Chantier :" & chantier & vbCrLf & "Produit :" & nom & vbCrLf & "Semaine : " & col, vbExclamation, "A commander:" 

Set cas = .FindNext(cas) 

Loop While Not cas Is Nothing And cas.Address <> termine 

End If 
End With 

'Fin 
MsgBox "Il n'y a pas d'autres commandes à passer.", , "A commander" 

End Sub 


Merci d'avance.
A voir également:

4 réponses

ghuysmans99 Messages postés 2496 Date d'inscription   Statut Contributeur Dernière intervention   340
 
Dim S As String
[...]
MsgBox zzz -> S = S & zzz & vbCrlf & vbCrlf
[...]
MsgBox "Pas d'autres commandes" -> MsgBox S
0
Chonbie Messages postés 183 Statut Membre 53
 
Si j'inscris MsgBox dans mon code ("MsgBox zzz") avant le MsgBox final, il va me la faire apparaître non?

Merci de ton aide ;D
0
Paf
 
bonjour

tu peux essayer en modifiant ton code:

... 
Message=Message & vbCrLf & "Chantier :" & chantier & vbCrLf & "Produit :" & nom & vbCrLf & "Semaine : " & col, vbExclamation, "A commander:"  
' a chaque passage de boucle on rajoute dans la variable Message
Set cas = .FindNext(cas)  

Loop While Not cas Is Nothing And cas.Address <> termine  

Msgbox Message 
Exit Sub 
End If  
End With 
...
bonne suite
0
pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   2 770
 
Bonjour,
Pour rebondir sur la bonne proposition de Paf, je passerais effectivement par une variable intermédiaire de type String :
Dim Message As String
'blabla
Do 
ligne = cas.Row 
col = cas.Column - 5 
nom = Range("D" & ligne).Formula 
chant = Range("B" & ligne).End(xlUp).Row 
chantier = Range("B" & chant).Formula 

'Message Box 
Message = Message & vbCrLf &  "Chantier : " & chantier & " Produit : " & nom & " Semaine : " & col
Set cas = .FindNext(cas) 

Loop While Not cas Is Nothing And cas.Address <> termine
Msgbox Message
Exit Sub

La différence avec Paf tient dans les passages à la ligne qui vont rendre le résultat difficilement compréhensible.
0