Búsqueda o filtro con el evento click de un combobox
Estoy intentando programar un código que me devuelva los datos de una tabla al seleccionar un dato dentro del combobox.
Debería funcionar de la siguiente forma:
Busco los datos en un combobox y me rellena el txt_equipo, después selecciono en el cbo_tarea_prin una opción y los datos se me muestran en el listbox1.
Ahora mismo al ejecutar el cbo_tarea_prin el listbox se cargan los datos filtrados por el txt_equipo sin tener en cuenta la selección del cbo_tarea_prin.
Espero puedan instruirme.
Private Sub cbo_tarea_prin_Click()
Dim Fila, final As Integer
'
Fila = 2
With Hoja7
For Fila = 2 To final
If txt_equipo = Hoja7.Cells(Fila, 1) Then
cbo_tarea_prin = Hoja7.Cells(Fila, 2)
Exit For
End If
Next
If txt_equipo.Value = Empty Then
ListBox1.Clear
End If
Me.ListBox1.ColumnCount = 10
Me.ListBox1.ColumnWidths = "30pt;115pt;50pt;50pt;50pt;50pt;50pt;100pt;50pt;50pt"
ListBox1.Clear
items = Hoja7.Range("equipos").CurrentRegion.Rows.Count
For i = 2 To items
If LCase(Hoja7.Cells(i, 1).Value) Like "*" & LCase(txt_equipo.Value) Then 'LCase(txt_equipo.Value) Like "*" &
ListBox1. AddItem Hoja7.Cells(i, 3)
ListBox1. List(ListBox1.ListCount - 1, 1) = Hoja7.Cells(i, 7)
ListBox1. List(ListBox1.ListCount - 1, 2) = Hoja7.Cells(i, 8)
ListBox1. List(ListBox1.ListCount - 1, 3) = Hoja7.Cells(i, 9)
ListBox1. List(ListBox1.ListCount - 1, 4) = Hoja7. Cells(i, 10)
ListBox1. List(ListBox1.ListCount - 1, 5) = Hoja7. Cells(i, 11)
ListBox1. List(ListBox1.ListCount - 1, 6) = Hoja7. Cells(i, 12)
ListBox1. List(ListBox1.ListCount - 1, 7) = Hoja7. Cells(i, 13)
ListBox1. List(ListBox1.ListCount - 1, 8) = Hoja7. Cells(i, 14)
ListBox1. List(ListBox1.ListCount - 1, 9) = Hoja7. Cells(i, 15)
End If
Next i
Exit Sub
End With
End Sub
1 respuesta
Respuesta de Programar Excel
1