Function FindAll(ByVal sText As String, ByRef oSht As Worksheet, ByRef sRange As String, ByRef arMatches() As String) As Boolean ' -------------------------------------------------------------------------------------------------------------- ' FindAll - To find all instances of the1 given string and return the row numbers. ' If there are not any matches the function will return false ' -------------------------------------------------------------------------------------------------------------- On Error GoTo Err_Trap Dim rFnd As Range ' Range Object Dim iArr As Integer ' Counter for Array Dim rFirstAddress ' Address of the First Find ' ----------------- ' Clear the Array ' ----------------- Erase arMatches Set rFnd = oSht.Range(sRange).Find(what:=sText, LookIn:=xlValues, lookAt:=xlPart) If Not rFnd Is Nothing Then rFirstAddress = rFnd.Address Do Until rFnd Is Nothing iArr = iArr + 1 ReDim Preserve arMatches(iArr) arMatches(iArr) = rFnd.Row 'rFnd.Address pour adresse complete ' rFnd.Row Pour N° de ligne Set rFnd = oSht.Range(sRange).FindNext(rFnd) If rFnd.Address = rFirstAddress Then Exit Do ' Do not allow wrapped search Loop FindAll = True Else ' ---------------------- ' No Value is Found ' ---------------------- FindAll = False End If ' ----------------------- ' Error Handling ' ----------------------- Err_Trap: If Err <> 0 Then MsgBox Err.Number & " " & Err.Description, vbInformation, "Find All" Err.Clear FindAll = False Exit Function End If End Function
Sub Exemple_util_Findall() Dim arTemp() As String 'variable tableau pour la fonction Findall Dim ValCherchee as string ValCherchee="test" Dim Nom_Feuil as string Nom_Feuil = "Feuil1" '--------------------------------------------------------------- bFound = FindAll(ValCherchee, Sheets(Nom_Feuil), ma_plage, arTemp()) '--------------------------------------------------------------- If bFound = True Then Debug.Print "Nb occurences : " & UBound(arTemp) For X = 1 To UBound(arTemp) debug.print arTemp(X) Next End If End sub
Private Sub bouton_FindAll_Click() Dim arTemp() As String 'variable tableau pour la fonction Findall Dim ValCherchee As String ValCherchee = Me.T_immat.Value Dim Nom_Feuil As String Nom_Feuil = "Feuil1" Dim ma_plage As String ma_plage = "A1:A1000" '--------------------------------------------------------------- bFound = FindAll(ValCherchee, Sheets(Nom_Feuil), ma_plage, arTemp()) '--------------------------------------------------------------- 'Initialisation de la ListBox ListBox1.ColumnCount = 3 ListBox1.ColumnWidths = "20;40;80" If bFound = True Then Debug.Print "Nb occurences : " & UBound(arTemp) For x = 1 To UBound(arTemp) Debug.Print arTemp(x) '------------------------- 'remplissage ListBox '------------------------- 'première colonne Me.ListBox1.AddItem (arTemp(x)) 'deuxième colonne ListBox1.List(ListBox1.ListCount - 1, 1) = Sheets(1).Cells(arTemp(x), 1).Value 'troisième colonne ListBox1.List(ListBox1.ListCount - 1, 2) = Sheets(1).Cells(arTemp(x), 2).Value Next End If End Sub Private Sub ListBox1_Click() 'Lors du click dans ma liste : 'Remplissage des TextBox : ligneSelect = ListBox1.ListIndex valeur_colonne1 = ListBox1.List(ligneSelect, 0) valeur_Colonne2 = ListBox1.List(ligneSelect, 1) valeur_Colonne3 = ListBox1.List(ligneSelect, 2) Me.T_immat_detail.Value = valeur_Colonne2 Me.T_nom_detail.Value = valeur_Colonne3 End Sub
Private Sub CommandButton5_FindAll_Click()
Dim arTemp() As String 'variable tableau pour la fonction Findall
Dim ValCherchee As String
ValCherchee = Me.TextBox14.Value
Dim Nom_Feuil As String
Nom_Feuil = "Factures"
Dim ma_plage As String
ma_plage = "B1:B1000"
'---------------------------------------------------------------
bFound = Findall(ValCherchee, Sheets(Nom_Feuil), ma_plage, arTemp())
'---------------------------------------------------------------
'Initialisation de la ListBox
ListBox1.ColumnCount = 3
ListBox1.ColumnWidths = "20;40;80"
If bFound = True Then
Debug.Print "Nb occurences : " & UBound(arTemp)
For x = 1 To UBound(arTemp)
Debug.Print arTemp(x)
'-------------------------
'remplissage ListBox
'-------------------------
'première colonne
Me.ListBox1.AddItem (arTemp(x))
'deuxième colonne
ListBox1.List(ListBox1.ListCount - 1, 1) = Sheets(1).Cells(arTemp(x), 1).Value
'troisième colonne
ListBox1.List(ListBox1.ListCount - 1, 2) = Sheets(1).Cells(arTemp(x), 2).Value
ListBox1.List(ListBox1.ListCount - 1, 3) = Sheets(1).Cells(arTemp(x), 3).Value
ListBox1.List(ListBox1.ListCount - 1, 4) = Sheets(1).Cells(arTemp(x), 4).Value
ListBox1.List(ListBox1.ListCount - 1, 5) = Sheets(1).Cells(arTemp(x), 5).Value
ListBox1.List(ListBox1.ListCount - 1, 6) = Sheets(1).Cells(arTemp(x), 6).Value
ListBox1.List(ListBox1.ListCount - 1, 7) = Sheets(1).Cells(arTemp(x), 7).Value
Next
End If
End Sub
Private Sub ListBox1_Click()
'Lors tu click dans ma liste :
'Remplissage des TextBox :
ligneSelect = ListBox1.ListIndex
valeur_colonne1 = ListBox1.List(ligneSelect, 0)
valeur_Colonne2 = ListBox1.List(ligneSelect, 1)
valeur_Colonne3 = ListBox1.List(ligneSelect, 2)
valeur_Colonne4 = ListBox1.List(ligneSelect, 3)
valeur_Colonne5 = ListBox1.List(ligneSelect, 4)
valeur_Colonne6 = ListBox1.List(ligneSelect, 5)
valeur_Colonne7 = ListBox1.List(ligneSelect, 6)
Me.T_immat_detail.Value = valeur_Colonne2
Me.T_nom_detail.Value = valeur_Colonne3
End Sub
' Nombre de colonne de la listBox ListBox1.ColumnCount = 3 'Largeur des colonnes dans la listbox ListBox1.ColumnWidths = "20;40;80"
Je ne comprend pas la partie arTemp(x) ?
Me.T_immat_detail.Value = valeur_Colonne2
Me.T_nom_detail.Value = valeur_Colonne3
Me.Textbox1.Value = valeur_Colonne2 Me.Textbox2.Value = valeur_Colonne3 Me.Textbox3.Value = valeur_Colonne3 Me.Textbox4.Value = valeur_Colonne4 ' ...etc...
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub CommandButton5_FindAll_Click()
Dim arTemp() As String 'variable tableau pour la fonction Findall
Dim ValCherchee As String
ValCherchee = Me.TextBox14.Value
Dim Nom_Feuil As String
Nom_Feuil = "Factures"
Dim ma_plage As String
ma_plage = "B1:B1000"
'---------------------------------------------------------------
bFound = Findall(ValCherchee, Sheets(Nom_Feuil), ma_plage, arTemp())
'---------------------------------------------------------------
'Initialisation de la ListBox
ListBox1.ColumnCount = 8
ListBox1.ColumnWidths = "20;40;80"
If bFound = True Then
Debug.Print "Nb occurences : " & UBound(arTemp)
For x = 1 To UBound(arTemp)
Debug.Print arTemp(x)
'-------------------------
'remplissage ListBox
'-------------------------
'première colonne
Me.ListBox1.AddItem (arTemp(x))
'deuxième colonne
ListBox1.List(ListBox1.ListCount - 1, 1) = Sheets(1).Cells(arTemp(x), 1).Value
'troisième colonne
ListBox1.List(ListBox1.ListCount - 1, 2) = Sheets(1).Cells(arTemp(x), 2).Value
ListBox1.List(ListBox1.ListCount - 1, 3) = Sheets(1).Cells(arTemp(x), 3).Value
ListBox1.List(ListBox1.ListCount - 1, 4) = Sheets(1).Cells(arTemp(x), 4).Value
ListBox1.List(ListBox1.ListCount - 1, 5) = Sheets(1).Cells(arTemp(x), 5).Value
ListBox1.List(ListBox1.ListCount - 1, 6) = Sheets(1).Cells(arTemp(x), 6).Value
ListBox1.List(ListBox1.ListCount - 1, 7) = Sheets(1).Cells(arTemp(x), 7).Value
Next
End If
End Sub
Private Sub ListBox1_Click()
'Lors tu click dans ma liste :
'Remplissage des TextBox :
ligneSelect = ListBox1.ListIndex
valeur_colonne1 = ListBox1.List(ligneSelect, 0)
valeur_Colonne2 = ListBox1.List(ligneSelect, 1)
valeur_Colonne3 = ListBox1.List(ligneSelect, 2)
valeur_Colonne4 = ListBox1.List(ligneSelect, 3)
valeur_Colonne5 = ListBox1.List(ligneSelect, 4)
valeur_Colonne6 = ListBox1.List(ligneSelect, 5)
valeur_Colonne7 = ListBox1.List(ligneSelect, 6)
Me.TextBox15.Value = valeur_Colonne2
Me.TextBox16.Value = valeur_Colonne3
Me.TextBox17.Value = valeur_Colonne4
Me.TextBox18.Value = valeur_Colonne5
Me.TextBox19.Value = valeur_Colonne6
Me.TextBox20.Value = valeur_Colonne7
Me.TextBox21.Value = valeur_Colonne8
End Sub
ListBox1.ColumnWidths = "20;40;80"
Lorsque que je clique sur mon bouton rechercher (CommandButton5) rien ne se passe.Mets un POINT d'ARRET sur la ligne :
bFound = Findall(ValCherchee, Sheets(Nom_Feuil), ma_plage, arTemp())
ListBox1.ColumnWidths = "20;40;80;40;40;40;40;40"
Private Sub CommandButton5_FindAll_Click()
Dim arTemp() As String 'variable tableau pour la fonction Findall
Dim ValCherchee As String
ValCherchee = ConsulterFacture.TextBox14.Value
Dim Nom_Feuil As String
Nom_Feuil = "Factures"
Dim ma_plage As String
ma_plage = "B1:B1000"
'---------------------------------------------------------------
bFound = Findall(ValCherchee, Sheets(Nom_Feuil), ma_plage, arTemp())
'---------------------------------------------------------------
'Initialisation de la ListBox
ListBox1.ColumnCount = 8
ListBox1.ColumnWidths = "20;20;10;100;20;10;100"
If bFound = True Then
Debug.Print "Nb occurences : " & UBound(arTemp)
For x = 1 To UBound(arTemp)
Debug.Print arTemp(x)
'-------------------------
'remplissage ListBox
'-------------------------
'première colonne
ConsulterFacture.ListBox1.AddItem (arTemp(x))
'deuxième colonne
ListBox1.List(ListBox1.ListCount - 1, 1) = Sheets("Factures").Cells(arTemp(x), 1).Value
'troisième colonne
ListBox1.List(ListBox1.ListCount - 1, 2) = Sheets("Factures").Cells(arTemp(x), 2).Value
ListBox1.List(ListBox1.ListCount - 1, 3) = Sheets("Factures").Cells(arTemp(x), 3).Value
ListBox1.List(ListBox1.ListCount - 1, 4) = Sheets("Factures").Cells(arTemp(x), 4).Value
ListBox1.List(ListBox1.ListCount - 1, 5) = Sheets("Factures").Cells(arTemp(x), 5).Value
ListBox1.List(ListBox1.ListCount - 1, 6) = Sheets("Factures").Cells(arTemp(x), 6).Value
ListBox1.List(ListBox1.ListCount - 1, 7) = Sheets("Factures").Cells(arTemp(x), 7).Value
Next
End If
End Sub
Private Sub ListBox1_Click()
'Lors tu click dans ma liste :
'Remplissage des TextBox :
ligneSelect = ListBox1.ListIndex
valeur_colonne1 = ListBox1.List(ligneSelect, 0)
valeur_Colonne2 = ListBox1.List(ligneSelect, 1)
valeur_Colonne3 = ListBox1.List(ligneSelect, 2)
valeur_Colonne4 = ListBox1.List(ligneSelect, 3)
valeur_Colonne5 = ListBox1.List(ligneSelect, 4)
valeur_Colonne6 = ListBox1.List(ligneSelect, 5)
valeur_Colonne7 = ListBox1.List(ligneSelect, 6)
ConsulterFacture.TextBox15.Value = valeur_Colonne2
ConsulterFacture.TextBox16.Value = valeur_Colonne3
ConsulterFacture.TextBox17.Value = valeur_Colonne4
ConsulterFacture.TextBox18.Value = valeur_Colonne5
ConsulterFacture.TextBox19.Value = valeur_Colonne6
ConsulterFacture.TextBox20.Value = valeur_Colonne7
ConsulterFacture.TextBox21.Value = valeur_Colonne8
End Sub
orsque je clique sur "rechercher" rien ne se passe encore une fois.As tu mis un POINT D'ARRET dans ton code... puis tester en MODE PAS A PAS ?????
bFound = Findall(ValCherchee, Sheets(Nom_Feuil), ma_plage, arTemp())
bFound = Findall(ValCherchee, Sheets(Nom_Feuil), ma_plage, arTemp())
J'ai vérifié le bon bouton est bien CommandButton5 ..
Private Sub CommandButton5_Click()
Private Sub CommandButton5_FindAll_Click()
Private Sub CommandButton5_Click()
'variable tableau pour la fonction Findall
Dim arTemp() As String
Dim ValCherchee As String
ValCherchee = ConsulterFacture.TextBox14.Value
Dim Nom_Feuil As String
Nom_Feuil = "Factures"
Dim ma_plage As String
ma_plage = "B1:B1000"
'---------------------------------------------------------------
bFound = FindAll(ValCherchee, Sheets(Nom_Feuil), ma_plage, arTemp())
'---------------------------------------------------------------
'Initialisation de la ListBox
ListBox1.ColumnCount = 8
ListBox1.ColumnWidths = "20;20;10;100;20;10;100"
If bFound = True Then
Debug.Print "Nb occurences : " & UBound(arTemp)
For x = 1 To UBound(arTemp)
Debug.Print arTemp(x)
'-------------------------
'remplissage ListBox
'-------------------------
'première colonne
ConsulterFacture.ListBox1.AddItem (arTemp(x))
'deuxième colonne
ListBox1.List(ListBox1.ListCount - 1, 1) = Sheets("Factures").Cells(arTemp(x), 1).Value
'troisième colonne
ListBox1.List(ListBox1.ListCount - 1, 2) = Sheets("Factures").Cells(arTemp(x), 2).Value
ListBox1.List(ListBox1.ListCount - 1, 3) = Sheets("Factures").Cells(arTemp(x), 3).Value
ListBox1.List(ListBox1.ListCount - 1, 4) = Sheets("Factures").Cells(arTemp(x), 4).Value
ListBox1.List(ListBox1.ListCount - 1, 5) = Sheets("Factures").Cells(arTemp(x), 5).Value
ListBox1.List(ListBox1.ListCount - 1, 6) = Sheets("Factures").Cells(arTemp(x), 6).Value
ListBox1.List(ListBox1.ListCount - 1, 7) = Sheets("Factures").Cells(arTemp(x), 7).Value
Next
End If
End Sub
Private Sub ListBox1_Click()
'Lors tu click dans ma liste :
'Remplissage des TextBox :
ligneSelect = ListBox1.ListIndex
valeur_colonne1 = ListBox1.List(ligneSelect, 0)
valeur_Colonne2 = ListBox1.List(ligneSelect, 1)
valeur_Colonne3 = ListBox1.List(ligneSelect, 2)
valeur_Colonne4 = ListBox1.List(ligneSelect, 3)
valeur_Colonne5 = ListBox1.List(ligneSelect, 4)
valeur_Colonne6 = ListBox1.List(ligneSelect, 5)
valeur_Colonne7 = ListBox1.List(ligneSelect, 6)
ConsulterFacture.TextBox15.Value = valeur_Colonne2
ConsulterFacture.TextBox16.Value = valeur_Colonne3
ConsulterFacture.TextBox17.Value = valeur_Colonne4
ConsulterFacture.TextBox18.Value = valeur_Colonne5
ConsulterFacture.TextBox19.Value = valeur_Colonne6
ConsulterFacture.TextBox20.Value = valeur_Colonne7
ConsulterFacture.TextBox21.Value = valeur_Colonne8
End Sub
ConsulterFacture.ListBox1.AddItem (arTemp(x))
'deuxième colonne
ListBox1.List(ListBox1.ListCount - 1, 1) = Sheets("Factures").Cells(arTemp(x), 1).Value
'troisième colonne
ListBox1.List(ListBox1.ListCount - 1, 2) = Sheets("Factures").Cells(arTemp(x), 2).Value
ListBox1.List(ListBox1.ListCount - 1, 3) = Sheets("Factures").Cells(arTemp(x), 3).Value
ListBox1.List(ListBox1.ListCount - 1, 4) = Sheets("Factures").Cells(arTemp(x), 4).Value
ListBox1.List(ListBox1.ListCount - 1, 5) = Sheets("Factures").Cells(arTemp(x), 5).Value
ListBox1.List(ListBox1.ListCount - 1, 6) = Sheets("Factures").Cells(arTemp(x), 6).Value
ListBox1.List(ListBox1.ListCount - 1, 7) = Sheets("Factures").Cells(arTemp(x), 7).Value
Et enfin, les indices négatifs = False ?Là.. je ne sais pas de quoi tu me parles..... Où ça des indices négatifs.... et = False ??
12 juin 2014 à 09:51
Pour ce sujet je dois créer dans l'UserForm un textbox dans lequel sera affiché tous les éléments trouvés? ou c'est une zone liste ? Ou encore plusieurs TextBox à la suite ?
J'ai commencé à faire ces lignes :
(pour retrouver l'immatriculation)
(Pour retrouver les factures correspondantes
12 juin 2014 à 10:41
Une ListBox pour afficher la référence des différentes factures
http://silkyroad.developpez.com/VBA/ControlesUserForm/#LII-G
Puis des TextBox qui afficheront les informations de la facture sélectionnée dans ta liste.
Et donc, dans ton code.. à quel endroit tu va "alimenter" ta liste...?.. hé bien ça sera dans
dans la boucle for :
12 juin 2014 à 14:25
Mais ca ne marche pas encore.
Je veux qu'en entrant l'immatriculation + click sur "rechercher" ça donne la liste des factures correspondantes au véhicule.
Et que ensuite une fois clique sur l'une des factures ça remplisse les champs des textbox correspondants
12 juin 2014 à 14:44
Si tu l'avais fait... tu aurais compris que le Numéro de ligne correspondant à ta recherche se trouve dans le tableau arrTemp(x)
Regardes dans le VBE, dans la fenêtre d'execution, ce que t'affiche la ligne de code :
... cette ligne de code t'affiche les N° des différentes lignes qui contiennent un résultat pour ta recherche...