B
ben
Guest
Bonjour le forum
j'ai un souci concernant une comparaison de chaines de caractère
J'ai une listbox avec différente valeurs
TOTO
TITI
j'ai le code suivant pour l'extraire en chaine de caractère :
Dim sTxt As String
Dim resultat As String
For irow = 0 To UserForm1.listbox2.ListCount - 1
If sTxt = "" Then
sTxt = UserForm1.listbox2(irow)
Else
sTxt = sTxt & "+" & UserForm1.listbox2.List(irow)
End If
Next irow
resultat = sTxt
resultat est donc égal à "TOTO+TITI"
je compare ensuite cette chaine à une cellule, si il me trouve la même chaine il m'affiche dans une textbox la valeur de l'offset(0,2)
Code suivant :
If UserForm1.listbox2.ListCount >= 2 Then
Sheets("gestion").Select
For Each orge In ActiveSheet.Range("A3:A" & ActiveSheet.Range("B65536").End(xlUp).Row)
If orge.Value = UserForm1.cbx_choix.Value _
And orge.Offset(0, 1).Value = UserForm1.txt_choix_item.Value _
And orge.Offset(0, 2).Value = resultat Then
UserForm1.TextBox1.Value = orge.Offset(0, 3).Value
Else
UserForm1.TextBox1.Value = "inexistant"
UserForm1.CommandButton5.Visible = True
End If
Next orge
Mon problème est que si il y a comparaison entre "TOTO+TITI" et "TITI+TOTO" il m'affiche inexistant alors qu'il devrait m'afficher un N° correspondant à l'offset(0,2)
Comment puis je faire pour gérer une comparaison de chaine ds un ordre indifférent ?
Merci pour votre aide
j'ai un souci concernant une comparaison de chaines de caractère
J'ai une listbox avec différente valeurs
TOTO
TITI
j'ai le code suivant pour l'extraire en chaine de caractère :
Dim sTxt As String
Dim resultat As String
For irow = 0 To UserForm1.listbox2.ListCount - 1
If sTxt = "" Then
sTxt = UserForm1.listbox2(irow)
Else
sTxt = sTxt & "+" & UserForm1.listbox2.List(irow)
End If
Next irow
resultat = sTxt
resultat est donc égal à "TOTO+TITI"
je compare ensuite cette chaine à une cellule, si il me trouve la même chaine il m'affiche dans une textbox la valeur de l'offset(0,2)
Code suivant :
If UserForm1.listbox2.ListCount >= 2 Then
Sheets("gestion").Select
For Each orge In ActiveSheet.Range("A3:A" & ActiveSheet.Range("B65536").End(xlUp).Row)
If orge.Value = UserForm1.cbx_choix.Value _
And orge.Offset(0, 1).Value = UserForm1.txt_choix_item.Value _
And orge.Offset(0, 2).Value = resultat Then
UserForm1.TextBox1.Value = orge.Offset(0, 3).Value
Else
UserForm1.TextBox1.Value = "inexistant"
UserForm1.CommandButton5.Visible = True
End If
Next orge
Mon problème est que si il y a comparaison entre "TOTO+TITI" et "TITI+TOTO" il m'affiche inexistant alors qu'il devrait m'afficher un N° correspondant à l'offset(0,2)
Comment puis je faire pour gérer une comparaison de chaine ds un ordre indifférent ?
Merci pour votre aide