• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

2 zoekfilters tegelijk over verschillende kolommen.

Status
Niet open voor verdere reacties.

patrick89

Gebruiker
Lid geworden
9 jun 2010
Berichten
16
Iemand een idee hoe ik dit werkend krijg:

Heb een zoekvenster gemaakt waarmee je 1 kolom kan filtreren., nu wil ik nadat ik in zoekvenster 1 een waarde heb ingevoegd , ik in zoekvenster 2 hetzelfde kan doen voor de kolom ernaast maar hier filtert hij niet meer, maar laat hij weer alle records zien als ik wat intyp, als ik zoekvenster 1 leeghou en iets intyp in zoekvenster 2 verwijdert hij alle lege cellen , maar filtert verder niet op inhoud.

Dit is de code:

Private Sub TextBox1_Change()

Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If Len(TextBox1.Value) = 0 And Len(TextBox2.Value) = 0 Then
ElseIf Len(TextBox1.Value) <> 0 And Len(TextBox2.Value) = 0 Then
ActiveSheet.Range("$F$21:$F$1337").AutoFilter field:=1, Criteria1:="=*" & TextBox1.Value & "*", VisibleDropDown:=False
Application.ScreenUpdating = True
End If
End Sub


Private Sub TextBox2_Change()
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If Len(TextBox1.Value) = 0 And Len(TextBox2.Value) = 0 Then
ElseIf Len(TextBox2.Value) <> 0 And Len(TextBox1.Value) = 0 Then
ActiveSheet.Range("$G$21:$G$1337").AutoFilter field:=1, Criteria1:="=*" & TextBox1.Value & "*", VisibleDropDown:=False
Application.ScreenUpdating = True
End If
End Sub

Ik begin net hiermee , dus misschien zie ik iets heel stoms over het hoofd:o
 
Probeer het zo eens Patrick.
Code:
Private Sub TextBox1_Change()
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If Len(TextBox1.Value) = 0 And Len(TextBox2.Value) = 0 Then
ElseIf Len(TextBox1.Value) <> 0 And Len(TextBox2.Value) = 0 Then
ActiveSheet.Range("$F$21:$F$1337").AutoFilter field:=1, Criteria1:="=*" & TextBox1.Value & "*", VisibleDropDown:=False
Application.ScreenUpdating = True
End If
End Sub


Private Sub TextBox2_Change()
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If Len(TextBox1.Value) = 0 And Len(TextBox2.Value) = 0 Then
ElseIf Len(TextBox2.Value) <> 0 And Len(TextBox1.Value) <> 0 Then
ActiveSheet.Range("$G$21:$G$1337").AutoFilter field:=1, Criteria1:="=*" & TextBox2.Value & "*", VisibleDropDown:=False
Application.ScreenUpdating = True
End If
End Sub
 
Dankje dat werkte super!:D

En als ik nu nog 2 filters wil toevoegen hoe ga ik dan te werk?
 
Ik heb hem nu zo :

Code:
Private Sub TextBox1_Change()
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If Len(TextBox1.Value) = 0 And Len(TextBox2.Value) = 0 And Len(TextBox3.Value) = 0 Then
ElseIf Len(TextBox1.Value) <> 0 And Len(TextBox2.Value) = 0 And Len(TextBox3.Value) <> 0 Then
ActiveSheet.Range("$F$21:$F$25000").AutoFilter field:=1, Criteria1:="=*" & TextBox1.Value & "*", VisibleDropDown:=False
Application.ScreenUpdating = True
End If
End Sub


Private Sub TextBox2_Change()
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If Len(TextBox1.Value) = 0 And Len(TextBox2.Value) = 0 And Len(TextBox3.Value) = 0 Then
ElseIf Len(TextBox2.Value) <> 0 And Len(TextBox1.Value) <> 0 And Len(TextBox3.Value) <> 0 Then
ActiveSheet.Range("$G$21:$G$25000").AutoFilter field:=1, Criteria1:="=*" & TextBox2.Value & "*", VisibleDropDown:=False
Application.ScreenUpdating = True
End If
End Sub

Private Sub TextBox3_Change()
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If Len(TextBox1.Value) = 0 And Len(TextBox2.Value) = 0 And Len(TextBox3.Value) = 0 Then
ElseIf Len(TextBox3.Value) <> 0 And Len(TextBox1.Value) <> 0 And Len(TextBox2.Value) <> 0 Then
ActiveSheet.Range("$H$21:$H$25000").AutoFilter field:=1, Criteria1:="=*" & TextBox3.Value & "*", VisibleDropDown:=False
Application.ScreenUpdating = True
End If
End Sub

Maar hij werkt helaas niet :( iemand een idee wat er fout zit?
 
Zo dan Patrick.

Code:
Private Sub TextBox1_Change()
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If Len(TextBox1.Value) = 0 And Len(TextBox2.Value) = 0 And Len(TextBox3.Value) = 0 Then
ElseIf Len(TextBox1.Value) <> 0 And Len(TextBox2.Value) = 0 And Len(TextBox3.Value) = 0 Then
ActiveSheet.Range("$F$21:$F$25000").AutoFilter field:=1, Criteria1:="=*" & TextBox1.Value & "*", VisibleDropDown:=False
Application.ScreenUpdating = True
End If
End Sub


Private Sub TextBox2_Change()
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If Len(TextBox1.Value) = 0 And Len(TextBox2.Value) = 0 And Len(TextBox3.Value) = 0 Then
ElseIf Len(TextBox2.Value) <> 0 And Len(TextBox1.Value) <> 0 And Len(TextBox3.Value) = 0 Then
ActiveSheet.Range("$G$21:$G$25000").AutoFilter field:=1, Criteria1:="=*" & TextBox2.Value & "*", VisibleDropDown:=False
Application.ScreenUpdating = True
End If
End Sub

Private Sub TextBox3_Change()
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If Len(TextBox1.Value) = 0 And Len(TextBox2.Value) = 0 And Len(TextBox3.Value) = 0 Then
ElseIf Len(TextBox3.Value) <> 0 And Len(TextBox1.Value) <> 0 And Len(TextBox2.Value) <> 0 Then
ActiveSheet.Range("$H$21:$H$25000").AutoFilter field:=1, Criteria1:="=*" & TextBox3.Value & "*", VisibleDropDown:=False
Application.ScreenUpdating = True
End If
End Sub
 
Zo dan Patrick.

Code:
Private Sub TextBox1_Change()
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If Len(TextBox1.Value) = 0 And Len(TextBox2.Value) = 0 And Len(TextBox3.Value) = 0 Then
ElseIf Len(TextBox1.Value) <> 0 And Len(TextBox2.Value) = 0 And Len(TextBox3.Value) = 0 Then
ActiveSheet.Range("$F$21:$F$25000").AutoFilter field:=1, Criteria1:="=*" & TextBox1.Value & "*", VisibleDropDown:=False
Application.ScreenUpdating = True
End If
End Sub


Private Sub TextBox2_Change()
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If Len(TextBox1.Value) = 0 And Len(TextBox2.Value) = 0 And Len(TextBox3.Value) = 0 Then
ElseIf Len(TextBox2.Value) <> 0 And Len(TextBox1.Value) <> 0 And Len(TextBox3.Value) = 0 Then
ActiveSheet.Range("$G$21:$G$25000").AutoFilter field:=1, Criteria1:="=*" & TextBox2.Value & "*", VisibleDropDown:=False
Application.ScreenUpdating = True
End If
End Sub

Private Sub TextBox3_Change()
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If Len(TextBox1.Value) = 0 And Len(TextBox2.Value) = 0 And Len(TextBox3.Value) = 0 Then
ElseIf Len(TextBox3.Value) <> 0 And Len(TextBox1.Value) <> 0 And Len(TextBox2.Value) <> 0 Then
ActiveSheet.Range("$H$21:$H$25000").AutoFilter field:=1, Criteria1:="=*" & TextBox3.Value & "*", VisibleDropDown:=False
Application.ScreenUpdating = True
End If
End Sub

Zo werkt hij super ! Bedankt harry :D
 
ik heb nu nog 1 probleem

5d8qar.png


Zoals je ziet werkt de filter niet helemaal optimaal.

Als ik audi intyp pakt hij alle audi's . als ik dan het type invoer zoekt hij weer alle types in dat veld. En vergeet hij het filter bij het merk :eek:

Is dit op te lossen misschien?
 
Probeer eens of het zo beter gaat als je het sterretje weg laat.
Criteria1:="=" i.p.v. Criteria1:="=*"
 
Probeer dit eens Patrick.
Code:
Private Sub TextBox1_Change()
  ActiveSheet.Range("F2:H25000").AutoFilter Field:=1, Criteria1:=TextBox1.Value & "*", VisibleDropDown:=False
End Sub

Private Sub TextBox2_Change()
  ActiveSheet.Range("F2:H25000").AutoFilter Field:=2, Criteria1:=TextBox2.Value & "*", VisibleDropDown:=False
End Sub

Private Sub TextBox3_Change()
  ActiveSheet.Range("F2:H25000").AutoFilter Field:=3, Criteria1:=TextBox3.Value & "*", VisibleDropDown:=False
End Sub
 
Probeer dit eens Patrick.
Code:
Private Sub TextBox1_Change()
  ActiveSheet.Range("F2:H25000").AutoFilter Field:=1, Criteria1:=TextBox1.Value & "*", VisibleDropDown:=False
End Sub

Private Sub TextBox2_Change()
  ActiveSheet.Range("F2:H25000").AutoFilter Field:=2, Criteria1:=TextBox2.Value & "*", VisibleDropDown:=False
End Sub

Private Sub TextBox3_Change()
  ActiveSheet.Range("F2:H25000").AutoFilter Field:=3, Criteria1:=TextBox3.Value & "*", VisibleDropDown:=False
End Sub

Dat werkt helaas ook niet:( ,

Ik probeer het excel bestand up te loaden naar hier maar hij zegt invalid file hoe moet ik dit doen?
 
Werkt bij mij perfect, maar je zal je bestand moeten Zippen of Rarren denk ik.
 
ik zie het probleem al hij was veel te groot!

Heb even de onnodige onderdelen en tabbladen verwijdert en in .rar gezet.
 

Bijlagen

Ik zie het probleem ook al.
Je textbox3 heet textbox4.
Zo moet het werken volgens mij.
 

Bijlagen

Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan