XL 2019 Combobox affiche 2 fois Msgbox

Kevin38

XLDnaute Nouveau
Bonsoir à tous,

Suite à l'ajoute du "ComboBox1 = UCase(ComboBox1)" le message combobox s'affiche deux fois

Quelqu'un a-t-il une idée de l'affichage 2 x et la solution pour y remédier ?

Merci d'avance

VB:
Private Sub ComboBox1_Change()
     With Sheets("CLIENT")
          a = Application.Transpose(.Range("A2:A" & .[A65000].End(xlUp).Row).Value2)
     End With
    
     With ComboBox1
          Range("C5").Value = .Text
          ComboBox1 = UCase(ComboBox1)
          If Len(.Text) = 0 Then
               .List = a
               .ListRows = Application.Min(10, .ListCount)
          Else
               fl = Filter(a, .Text, 2, 0)
               Select Case UBound(fl)
                    Case -1: MsgBox "Il n'existe aucun client de ce nom !!!", vbInformation, "Information Recherche Client"
                    Case Else
                         .List = fl
                         .ListRows = Application.Min(10, .ListCount)
                         If UBound(fl) <> 0 Then .DropDown
               End Select
          End If
     End With
End Sub
 

Dranreb

XLDnaute Barbatruc
Bonsoir
Déclarez en tête de l'UserForm Private ExécutionInduite As Boolean
Au début de la ComboBox1_Change : If ExécutionInduite Then Exit Sub puis juste derrière ExécutionInduite = True. À la fin juste avant la End Sub : ExécutionInduite = False

Ou bien mettez ExécutionInduite = True devant la ComboBox1 = UCase(ComboBox1), et derrière elle ExécutionInduite = False
 

Kevin38

XLDnaute Nouveau
Bonsoir
Déclarez en tête de l'UserForm Private ExécutionInduite As Boolean
Au début de la ComboBox1_Change : If ExécutionInduite Then Exit Sub puis juste derrière ExécutionInduite = True. À la fin juste avant la End Sub : ExécutionInduite = False

Ou bien mettez ExécutionInduite = True devant la ComboBox1 = UCase(ComboBox1), et derrière elle ExécutionInduite = False
Bonsoir Dranreb,

Je n'ai pas trop bien compris mais est-ce comme ça
VB:
Private ExécutionInduite As Boolean
If ExécutionInduite Then Exit Sub
   ExécutionInduite = True
   ExécutionInduite = False
End if
End Sub

Private Sub ComboBox1_Change()
     With Sheets("CLIENT")
          a = Application.Transpose(.Range("A2:A" & .[A65000].End(xlUp).Row).Value2)
     End With
    
     With ComboBox1
          Range("C5").Value = .Text
          ComboBox1 = UCase(ComboBox1)
          If Len(.Text) = 0 Then
               .List = a
               .ListRows = Application.Min(10, .ListCount)
          Else
               fl = Filter(a, .Text, 2, 0)
               Select Case UBound(fl)
                    Case -1: MsgBox "Il n'existe aucun client de ce nom !!!", vbInformation, "Information Recherche Client"
                    Case Else
                         .List = fl
                         .ListRows = Application.Min(10, .ListCount)
                         If UBound(fl) <> 0 Then .DropDown
               End Select
          End If
     End With
End Sub
 

Kevin38

XLDnaute Nouveau
Non. Seule la déclaration de la varable globale ExécutionInduite doit être en tête de l'UserForm, en dehors de toute procédure. Les instructions exécutables doivent être dans la Private Sub ComboBox1_Change()
comme ça
VB:
Private ExécutionInduite As Boolean

Private Sub ComboBox1_Change()
     With Sheets("CLIENT")
          a = Application.Transpose(.Range("A2:A" & .[A65000].End(xlUp).Row).Value2)
     End With
    
     With ComboBox1
          Range("C5").Value = .Text
          ComboBox1 = UCase(ComboBox1)
          If Len(.Text) = 0 Then
               .List = a
               .ListRows = Application.Min(10, .ListCount)
          Else
               fl = Filter(a, .Text, 2, 0)
               Select Case UBound(fl)
                    Case -1: MsgBox "Il n'existe aucun client de ce nom !!!", vbInformation, "Information Recherche Client"
                    Case Else
                         .List = fl
                         .ListRows = Application.Min(10, .ListCount)
                         If UBound(fl) <> 0 Then .DropDown
               End Select
          End If
     End With
If ExécutionInduite Then Exit Sub
   ExécutionInduite = True
   ExécutionInduite = False
End if

End Sub
 

Dranreb

XLDnaute Barbatruc
Non, la If ExécutionInduite Then Exit Sub juste après la Private Sub ComboBox1_Change(),
la ExécutionInduite = True au plus tard juste avant la ComboBox1 = UCase(ComboBox1) (parce que c'est elle qui provoque sa réexécution) et la ExécutionInduite = False au plus tôt juste après la ComboBox1 = UCase(ComboBox1)
 

Kevin38

XLDnaute Nouveau
Non, la If ExécutionInduite Then Exit Sub juste après la Private Sub ComboBox1_Change(),
la ExécutionInduite = True au plus tard juste avant la ComboBox1 = UCase(ComboBox1) (parce que c'est elle qui provoque sa réexécution) et la ExécutionInduite = False au plus tôt juste après la ComboBox1 = UCase(ComboBox1)
J'éspere avoir le bon
VB:
Private ExécutionInduite As Boolean
Private Sub ComboBox1_Change(),If ExécutionInduite Then Exit Sub
     With Sheets("CLIENT")
          a = Application.Transpose(.Range("A2:A" & .[A65000].End(xlUp).Row).Value2)
     End With
    
     With ComboBox1
          Range("C5").Value = .Text
          ExécutionInduite = True
      ComboBox1 = UCase(ComboBox1)
      ExécutionInduite = False
          If Len(.Text) = 0 Then
               .List = a
               .ListRows = Application.Min(10, .ListCount)
          Else
               fl = Filter(a, .Text, 2, 0)
               Select Case UBound(fl)
                    Case -1: MsgBox "Il n'existe aucun client de ce nom !!!", vbInformation, "Information Recherche Client"
                    Case Else
                         .List = fl
                         .ListRows = Application.Min(10, .ListCount)
                         If UBound(fl) <> 0 Then .DropDown
               End Select
          End If
     End With
End Sub
 

Discussions similaires

Réponses
4
Affichages
191

Statistiques des forums

Discussions
312 095
Messages
2 085 249
Membres
102 835
dernier inscrit
Alexandrax971