Filtrar desde un ComboBox y vaciar al ListBox Excel VBA

Para Dante Amor

Amigo Dante buenas tardes deseo siguir implementando mi macro.

Quiero que en el COMBOBOX se filtre sólo nombres de los padres como se muestro en la imagen que intentaba modificar y luego arroje el detalle de multas al LISTBOX de las columnas FECHA// MOTIVO//MULTA  de la Hoja MULTAS

Le envié el archivo amigo Dante Saludos!

1 respuesta

Respuesta
1

Así quedaría el código

Public nombre
Private Sub CboLista_Change()
    nombre = CboLista.List(CboLista.ListIndex, 1)
    Lsmulta.Clear
    Set h = Sheets("Multas")
    Set r = h.Columns("D")
    Set b = r.Find(nombre, lookat:=xlWhole)
    If Not b Is Nothing Then
        ncell = b.Address
        Do
            'detalle
            Lsmulta.AddItem h.Cells(b.Row, "A")
            Lsmulta.List(Lsmulta.ListCount - 1, 1) = h.Cells(b.Row, "B")
            Lsmulta.List(Lsmulta.ListCount - 1, 2) = h.Cells(b.Row, "E")
            Set b = r.FindNext(b)
        Loop While Not b Is Nothing And b.Address <> ncell
    End If
End Sub
Private Sub UserForm_Initialize()
    Txthora.Text = Time
    Txtfecha.Text = Date
    Set h2 = Sheets("Multas")
    h2.Cells.EntireColumn.AutoFit
    CboLista.ColumnCount = 1
    col = Int(h2.Range("C1").Width) + 1 & ";" & _
          Int(h2.Range("D1").Width) + 1 & ";" & _
          Int(h2.Range("E1").Width)
    CboLista.ColumnWidths = col
    For i = 3 To h2.Range("A" & Rows.Count).End(xlUp).Row
        agregar h2, i, h2.Cells(i, "D")
    Next
     'Para monstrar detalle
    Set h = Sheets("Multas")
    Set r = h.Columns("D")
    Set b = r.Find(nombre, lookat:=xlWhole)
    If Not b Is Nothing Then
        ncell = b.Address
        Do
            'detalle
            Lsmulta.AddItem h.Cells(b.Row, "A")
            Lsmulta.List(Lsmulta.ListCount - 1, 1) = h.Cells(b.Row, "B")
            Lsmulta.List(Lsmulta.ListCount - 1, 2) = h.Cells(b.Row, "E")
            Set b = r.FindNext(b)
        Loop While Not b Is Nothing And b.Address <> ncell
    End If
End Sub
Sub agregar(h2, fila, dato)
'Por.Dante Amor
    For i = 0 To CboLista.ListCount - 1
        If StrComp(CboLista.List(i), dato, vbTextCompare) = 0 Then
            CboLista.List(i, 2) = Val(CboLista.List(i, 2)) + h2.Cells(fila, "E")
            Exit Sub
        End If
    Next
    CboLista.AddItem dato
    CboLista.List(CboLista.ListCount - 1, 1) = h2.Cells(fila, "D")
    CboLista.List(CboLista.ListCount - 1, 2) = h2.Cells(fila, "E")
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas