Listbox con selección y filtro para items con el mismo número

Sigo trabajando con el archivo que te envie, en este punto esto totalmente trancado, por lo que recurro a tu conocimiento.

El tema es el siguiente:

Cuento con tres listbox: el primero obtiene los datos de un hoja excel (calculos caloricos de un plato de comida), el plato de comida incluye una x cantidad de insumos, dichos insumos van a una segunda hoja de excel donde quedan registrados en su cantidad y tiene el mismo número que el numero interno del plato, es decir que cuando seleccione el plato numero 1 (sandwich de huevo) en la listbox 2, en el listbox 3 deberían aparecerme los datos de todos los insumos con el codigo 1 (pan, huevo, sal, etc.) para asi poder generar una hoja de pedidos.

El problema es que realmente no tengo la menor idea de como hacerlo, ya logre con uno de tus codigos que me mande los insumos a una hoja de excel (temp2) para que el tercer listbox se alimente de esta hoja de excel, sin embargo no se como hacer para que solo aparezcan los insumos con el numero 1 (o el numero que corresponda al plato) al primcipio.

Estoy enviado el archivo a tu correo.

1 Respuesta

Respuesta
2

Reviso el correo y te escribo una respuesta.

Te anexo la macro para cargar en el listbox3 los componentes.

Private Sub CommandButton5_Click()
'Por.Dante Amor
    Set h = Sheets("temp")
    h.Cells.Clear
    c = ListBox2.ColumnCount
    f = ListBox2.ListCount
    If f > 0 Then
        h.Range(h.Cells(1, 1), h.Cells(f, c)) = ListBox2.List
    End If
    For i = 0 To ListBox1.ColumnCount - 1
        h.Cells(f + 1, i + 1) = ListBox1.List(ListBox1.ListIndex, i)
    Next
    ListBox2.Clear
    ListBox2.List = h.Range(h.Cells(1, 1), h.Cells(f + 1, c)).Value
    ListBox3.Clear
    ListBox3.ColumnCount = 5
    '
    'Cargar componentes
    '
    Set h1 = Sheets("componentes")
    For i = 0 To ListBox2.ListCount - 1
        cod = ListBox2.List(i, 0)
        Set r = h1.Columns("A")
        Set b = r.Find(cod, lookat:=xlWhole)
        If Not b Is Nothing Then
            ncell = b.Address
            Do
                'detalle
                ListBox3. AddItem h1. Cells(b.Row, "A")
                ListBox3. List(ListBox3.ListCount - 1, 1) = h1. Cells(b.Row, "B")
                ListBox3. List(ListBox3.ListCount - 1, 2) = h1. Cells(b.Row, "C")
                ListBox3. List(ListBox3.ListCount - 1, 3) = h1. Cells(b.Row, "D")
                ListBox3. List(ListBox3.ListCount - 1, 4) = h1. Cells(b.Row, "E")
                Set b = r.FindNext(b)
            Loop While Not b Is Nothing And b.Address <> ncell
        End If
    Next
End Sub

Saludos.Dante Amor

Recuerda valorar la respuesta.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas