XL 2010 Rechercher tous les documents de travail

Mody200

XLDnaute Junior
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

  • Rechercher toutes les feuilles de calcul.xlsb
    123.7 KB · Affichages: 9
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) =...

Mody200

XLDnaute Junior
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:

Mody200

XLDnaute Junior
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
 

Mody200

XLDnaute Junior
Ce code est une recherche dans toutes les feuilles de calcul selon plusieurs critères, à savoir deux dates textbox9 et textbox 10 et deux critères combobox 1 et
Combobox 2, mais cela ne fonctionne pas pour moi lors d'une recherche dans des feuilles de calcul
 

Pièces jointes

  • Rechercher toutes les feuilles de calcul1.xlsb
    160.4 KB · Affichages: 2

Mody200

XLDnaute Junior
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
 

patricktoulon

XLDnaute Barbatruc
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 ;)
 

Mody200

XLDnaute Junior
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.
 

Mody200

XLDnaute Junior
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
 

Mody200

XLDnaute Junior
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.
 

Discussions similaires

Réponses
18
Affichages
625
Réponses
5
Affichages
349
Compte Supprimé 979
C
Réponses
2
Affichages
115

Statistiques des forums

Discussions
312 207
Messages
2 086 250
Membres
103 165
dernier inscrit
thithithi78