Este es un ejemplo de un código para realizar filtros por varios campos. En el ejemplo te estoy poniendo 2 combos y 2 textbox.
También te anexo mi archivo para que veas el funcionamiento y puedas adaptar el código a tus datos.
Archivo de filtros
Public campo1, campo2, campo3, campo4
Private Sub combobox1_Change() 'ID
'Por.Dante Amor
If IsNumeric(ComboBox1) Then
campo1 = ComboBox1.Value
Else
campo1 = IIf(Me.ComboBox1.Text = "", "", "*") & Me.ComboBox1.Text & IIf(Me.ComboBox1.Text = "", "", "*")
End If
filtrar
ComboBox1.SetFocus
End Sub
Private Sub ComboBox2_Change() 'Artículo
'Por.Dante Amor
If IsNumeric(ComboBox2) Then
campo2 = Me.ComboBox2.Value
Else
campo2 = ComboBox2.Text
End If
filtrar
ComboBox2.SetFocus
End Sub
Private Sub TextBox1_Change() 'Artículo
'Por.Dante Amor
If IsNumeric(TextBox1) Then
campo3 = Me.TextBox1.Value
Else
campo3 = IIf(Me.TextBox1.Text = "", "", "*") & Me.TextBox1.Text & IIf(Me.TextBox1.Text = "", "", "*")
End If
filtrar
TextBox1.SetFocus
End Sub
Private Sub TextBox2_Change() 'Artículo
'Por.Dante Amor
If IsNumeric(TextBox2) Then
campo4 = Me.TextBox2.Value
Else
campo4 = IIf(Me.TextBox2.Text = "", "", "*") & Me.TextBox2.Text & IIf(Me.TextBox2.Text = "", "", "*")
End If
filtrar
TextBox2.SetFocus
End Sub
Private Sub filtrar()
'Por.Dante Amor
Application.ScreenUpdating = False
Hoja5.Cells.Clear
With Hoja2
With .Range("A1:E" & .Range("A" & Rows.Count).End(xlUp).Row)
If campo1 <> "" Or campo2 <> "" Or campo3 <> "" Or campo4 <> "" Then
If campo1 <> "" Then .AutoFilter Field:=1, Criteria1:=campo1
If campo2 <> "" Then .AutoFilter Field:=2, Criteria1:=campo2
If campo3 <> "" Then .AutoFilter Field:=3, Criteria1:=campo3
If campo4 <> "" Then .AutoFilter Field:=5, Criteria1:=campo4
.Copy Hoja5.Range("A1")
u = Hoja5.Range("A" & Rows.Count).End(xlUp).Row
If u = 1 Then u = 2
ListBox1.RowSource = Hoja5.Name & "!A2:E" & u
Else
ListBox1.RowSource = Hoja2.Name & "!A2:E" & Hoja2.Range("A" & Rows.Count).End(xlUp).Row
End If
End With
If .AutoFilterMode Then .Range("A1").AutoFilter
End With
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_Activate()
'Por.Dante Amor
ListBox1.ColumnWidths = Int(Hoja2.[A1].Width + 1) & ";" & Int(Hoja2.[B1].Width + 1) & ";" & _
Int(Hoja2.[C1].Width + 1) & ";" & Int(Hoja2.[D1].Width + 1) & ";" & _
Int(Hoja2.[E1].Width + 1)
ListBox1.RowSource = Hoja2.Name & "!A2:E" & Hoja2.Range("A" & Rows.Count).End(xlUp).Row
ComboBox1.RowSource = Hoja4.Name & "!A2:A" & Hoja4.Range("A" & Rows.Count).End(xlUp).Row
ComboBox2.RowSource = Hoja3.Name & "!A2:A" & Hoja3.Range("A" & Rows.Count).End(xlUp).Row
End SubAvísame si tienes dudas.
Saludos. Dante Amor
Recuerda valorar la respuesta
Dante Amor que posibilidad hay que me pases un archivo que solo se filtre con el Combox2 y Combo3, porque quise utilizar los archivos que pasaste pero me perdí al tratar de editar el UserForm6desde ya muchas gracias, ya valore tu respuesta de arriba! - Andrés López Acosta
Hola: Podrías crear una nueva pregunta con lo que necesitas. Gracias por el voto. Saludos - Dante Amor