XL 2010 Rechercher tous les documents de travail

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Mody200

XLDnaute Occasionnel
Bonsoir

Je travaille sur un modèle utilisateur. Il s'agit d'un processus de recherche qui dépend de plusieurs critères. Il y a deux zones de texte (date) et deux zones de liste (client - code produit), mais cela dépend de la recherche de plusieurs feuilles de calcul et de leur récupération dans le listbox. Existe-t-il un code de recherche comme celui-ci ?

Veuillez afficher tous les chèques dans les colonnes jaunes de la listbox en fonction des options combobox et textbox (Date)
 

Pièces jointes

Solution
VB:
On Error Resume Next
Dim X As Worksheet
Dim k As Integer
Dim m As Date
Dim n As Date

ListBox1.Clear
rng1 = CDate(TextBox9.Value)
rng2 = CDate(TextBox10.Value)
rng3 = ComboBox1.Text
rng4 = ComboBox2.Text
dfr = 0
For Each X In ThisWorkbook.Worksheets
    ss = X.Cells(Rows.Count, 2).End(xlUp).Row
 For i = 2 To ss
If X.Cells(i, 6) Like "*" & rng3 & "*" And X.Cells(i, 4) Like "*" & rng4 & "*" And X.Cells(i, 2) >= rng1 And X.Cells(i, 2) <= rng2 Then
ListBox1.AddItem
ListBox1.List(dfr, 0) = X.Cells(i, 1)
ListBox1.List(dfr, 1) = Format(X.Cells(i, 2), "dd/mm/yyyy")
ListBox1.List(dfr, 2) = X.Cells(i, 3)
ListBox1.List(dfr, 3) = X.Cells(i, 4)
ListBox1.List(dfr, 4) = X.Cells(i, 5)
ListBox1.List(dfr, 5) = X.Cells(i, 6)
ListBox1.List(dfr, 6) =...
VB:
If TextBox8.Value = "" Then ListBox1.Clear: Exit Sub
Dim X As Worksheet
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
m = CDate(TextBox9.Value)
n = CDate(TextBox10.Value)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

ListBox1.Clear
k = 0
For Each X In ThisWorkbook.Worksheets
ss = X.Cells(Rows.Count, 2).End(xlUp).Row
For Each c In X.Range("b2:b" & ss)
b = InStr(c, ComboBox1)
b = InStr(c, ComboBox2)
b = InStr(c, TextBox9)
b = InStr(c, TextBox10)

'b = X.Cells(c, 3).Value - m >= 0
'b = X.Cells(X, 3).Value - n <= 0
If X.Cells(c, 3).Value - m >= 0 And X.Cells(c, 3).Value - n <= 0 Then

If b > 0 Then

                ListBox1.AddItem
                ListBox1.List(k, 0) = X.Cells(c.Row, 1).Value
                ListBox1.List(k, 1) = X.Cells(c.Row, 2).Value
                ListBox1.List(k, 2) = X.Cells(c.Row, 3).Value
                ListBox1.List(k, 3) = X.Cells(c.Row, 4).Value
                ListBox1.List(k, 4) = X.Cells(c.Row, 5).Value
                ListBox1.List(k, 5) = X.Cells(c.Row, 6).Value
                ListBox1.List(k, 6) = X.Cells(c.Row, 7).Value
                ListBox1.List(k, 7) = X.Cells(c.Row, 8).Value
                ListBox1.List(k, 8) = X.Cells(c.Row, 9).Value
                ListBox1.List(k, 9) = X.Cells(c.Row, 10).Value
             
                k = k + 1
                End If
               End If
        Next c
Next X
 
Dernière édition:
On Error Resume Next
If TextBox8.Value = "" Then ListBox1.Clear: Exit Sub

Dim X As Worksheet
Dim c As Range
Dim k As Integer
Dim m As Date
Dim n As Date

ListBox1.Clear
k = 0

m = CDate(TextBox9.Value)
n = CDate(TextBox10.Value)

For Each X In ThisWorkbook.Worksheets
ss = X.Cells(Rows.Count, 2).End(xlUp).Row
For Each c In X.Range("B2:B" & ss)
If (c.Value Like "*" & ComboBox1.Value & "*" Or c.Value Like "*" & ComboBox2.Value & "*") And (c.Offset(0, 2).Value >= m And c.Offset(0, 2).Value <= n) Then
ListBox1.AddItem
ListBox1.List(k, 0) = X.Cells(c.Row, 1).Value
ListBox1.List(k, 1) = CDate(X.Cells(c.Row, 2).Value)
ListBox1.List(k, 2) = X.Cells(c.Row, 3).Value
ListBox1.List(k, 3) = X.Cells(c.Row, 4).Value
ListBox1.List(k, 4) = X.Cells(c.Row, 5).Value
ListBox1.List(k, 5) = X.Cells(c.Row, 6).Value
ListBox1.List(k, 6) = X.Cells(c.Row, 7).Value
ListBox1.List(k, 7) = X.Cells(c.Row, 8).Value
ListBox1.List(k, 8) = X.Cells(c.Row, 9).Value
ListBox1.List(k, 9) = X.Cells(c.Row, 10).Value
k = k + 1
End If
Next c
Next X
 
VB:
On Error Resume Next
If TextBox8.Value = "" Then ListBox1.Clear: Exit Sub

Dim X As Worksheet
Dim c As Range
Dim k As Integer
Dim m As Date
Dim n As Date

ListBox1.Clear
k = 0

m = CDate(TextBox9.Value)
n = CDate(TextBox10.Value)

For Each X In ThisWorkbook.Worksheets
ss = X.Cells(Rows.Count, 2).End(xlUp).Row
For Each c In X.Range("B2:B" & ss)
If (c.Value Like "*" & ComboBox1.Value & "*" Or c.Value Like "*" & ComboBox2.Value & "*") And (c.Offset(0, 2).Value >= m And c.Offset(0, 2).Value <= n) Then
ListBox1.AddItem
ListBox1.List(k, 0) = X.Cells(c.Row, 1).Value
ListBox1.List(k, 1) = CDate(X.Cells(c.Row, 2).Value)
ListBox1.List(k, 2) = X.Cells(c.Row, 3).Value
ListBox1.List(k, 3) = X.Cells(c.Row, 4).Value
ListBox1.List(k, 4) = X.Cells(c.Row, 5).Value
ListBox1.List(k, 5) = X.Cells(c.Row, 6).Value
ListBox1.List(k, 6) = X.Cells(c.Row, 7).Value
ListBox1.List(k, 7) = X.Cells(c.Row, 8).Value
ListBox1.List(k, 8) = X.Cells(c.Row, 9).Value
ListBox1.List(k, 9) = X.Cells(c.Row, 10).Value
k = k + 1
End If
Next c
Next X
 
bonjour
il y a de l'amélioration dans tes code depuis le post 1
ce qui sous entends que tu a compris l'erreur que tu faisais en confondant un object cell et le numérique de son row (quoi que aucune variable de déclarée(dans ce contexte c'est pas judicieux))
ensuite
le test like *valeur* peut induire des ratés selon la position de la chaine recherchée dans la cellule ou si la cellule est égale à la chaine
tu devrais rester sur instr voir faire un test "=" si la chaine représente l'entièreté de la recherche

il te serait pas venu à l'idée des fois😉de faire un autofilter selon tes critères combo et textebox et de récupérer la liste des restants donc les specialcells pour alimenter ta listbox
je dis ça moi je dis rien hein 😉
 
bonjour patricktoulon
Je suis d'accord avec toi pour rester sur instr et tester "=" si la chaîne représente l'intégralité de la recherche

Cependant, lors du choix de certains critères, le processus de recherche ne réussit pas selon les critères. Il y a une erreur dans le code, et je ne sais pas où se trouve l'erreur.
 
VB:
On Error Resume Next
Dim X As Worksheet
Dim k As Integer
Dim m As Date
Dim n As Date

ListBox1.Clear
rng1 = CDate(TextBox9.Value)
rng2 = CDate(TextBox10.Value)
rng3 = ComboBox1.Text
rng4 = ComboBox2.Text
dfr = 0
For Each X In ThisWorkbook.Worksheets
    ss = X.Cells(Rows.Count, 2).End(xlUp).Row
 For i = 2 To ss
If X.Cells(i, 6) Like "*" & rng3 & "*" And X.Cells(i, 4) Like "*" & rng4 & "*" And X.Cells(i, 2) >= rng1 And X.Cells(i, 2) <= rng2 Then
ListBox1.AddItem
ListBox1.List(dfr, 0) = X.Cells(i, 1)
ListBox1.List(dfr, 1) = Format(X.Cells(i, 2), "dd/mm/yyyy")
ListBox1.List(dfr, 2) = X.Cells(i, 3)
ListBox1.List(dfr, 3) = X.Cells(i, 4)
ListBox1.List(dfr, 4) = X.Cells(i, 5)
ListBox1.List(dfr, 5) = X.Cells(i, 6)
ListBox1.List(dfr, 6) = X.Cells(i, 7)
ListBox1.List(dfr, 7) = X.Cells(i, 8)
ListBox1.List(dfr, 8) = X.Cells(i, 9)
ListBox1.List(dfr, 9) = X.Cells(i, 10)
ListBox1.List(dfr, 10) = X.Cells(i, 11) '.Value
ListBox1.List(dfr, 11) = X.Cells(i, 12) '.Value
dfr = dfr + 1
                End If
    Next i
Next X
Call Main
Call Sort
 
Bonjour
Screenshot_2023-09-18-13-42-10-46_99c04817c0de5652397fc8b56c3b3817.jpg

Le problème a été résolu à l'aide du code, mais il y a ici un problème avec l'organisation des données par date dans la liste. Après avoir sélectionné les quatre critères, il y a les trois dernières lignes qui ne sont pas organisées et ne sont pas formatées dans la liste.
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
5
Affichages
464
Réponses
4
Affichages
690
  • Question Question
Microsoft 365 Question code VBA
Réponses
2
Affichages
387
Réponses
5
Affichages
527
Compte Supprimé 979
C
Retour