Como crear listbox en excel vba para reportar con rangos de fechas o periodo a elegir

Tengo una consulta, como puedo crear un listbox de rango de fechas, tengo una planilla de inventarios donde yo voy registrando los movimientos de entradas y salidas de un articulo especifico, lo que quisiera es reportar por rango de fechas en la hoja “Resumen” de todos los artículos o de un articulo especifico tildando una casilla donde me estire todos los artículos y también quiero una opción donde no quiera todos los artículos sino ingresar el código y donde pueda estirar de acuerdo a un listbox “desde fecha” y “hasta la fecha” todos los movimientos de entradas y salidas si me podrias ayudar, te enviare por mail la planilla para que puedas mirar.

Respuesta
1

H o la: Reviso el correo y te aviso si tengo dudas.

Te anexo la macro

Private Sub CommandButton1_Click()
'Por.Dante Amor
    Set h1 = Sheets("RESUMEN")
    Set h2 = Sheets("INVENT")
    '
    'limpiar hoja
    h1.Range("A9:G" & Rows.Count).ClearContents
    If TextBox1 = "" And TextBox2 = "" Then
        MsgBox "Entra un Código o un Artículo"
        Exit Sub
    End If
    '
    If TextBox1 <> "" Then
        cve = TextBox1
        col = "B"
    Else
        cve = TextBox2
        col = "C"
    End If
    If IsNumeric(cve) Then cve = Val(cve)
    '
    Set b = h2.Columns(col).Find(cve, lookat:=xlWhole, LookIn:=xlValues)
    If b Is Nothing Then
        MsgBox "No existe el dato : " & cve
        Exit Sub
    End If
    '
    cod = h2.Cells(b.Row, "B")
    art = h2.Cells(b.Row, "C")
    '
    existe = False
    For Each h In Sheets
        If LCase(h.Name) = LCase(cod) Then
            existe = True
            Exit For
        End If
    Next
    If existe = False Then
        MsgBox "No existe la hoja: " & cod
        Exit Sub
    End If
    '
    If TextBox3 = "" Then
        fechas = ""
    Else
        fechas = "1"
        If Not IsDate(TextBox3) Then
            MsgBox "La fecha inicial no es correcta"
            Exit Sub
        End If
        If Not IsDate(TextBox4) Then
            MsgBox "La fecha final no es correcta"
            Exit Sub
        End If
        fecini = CDate(TextBox3)
        fecfin = CDate(TextBox4)
    End If
    '
    Application.ScreenUpdating = False
    '
    Set h3 = Sheets("" & cod)
    'Poner datos:
    h1.[B3] = cod
    h1.[D3] = art
    h1.[B5] = fecini
    h1.[D5] = fecfin
    '
    fila = 9
    h1.Cells(fila, "A") = h3.Cells(14, "L")
    u3 = h3.Range("B" & Rows.Count).End(xlUp).Row
    h1.Cells(fila, "F") = h3.Cells(u3, "M")
    For i = 15 To u3
        If fechas = "" Then
            fecini = h3.Cells(i, "B")
            fecfin = h3.Cells(i, "B")
        End If
        If h3.Cells(i, "B") >= fecini And h3.Cells(i, "B") <= fecfin Then
            Select Case LCase(Left(h3.Cells(i, "C"), 3))
                Case "com"
                    cantidad = h3.Cells(i, "F")
                    h1.Cells(fila, "B") = h1.Cells(fila, "B") + cantidad
                Case "ven"
                    cantidad = h3.Cells(i, "I")
                    h1.Cells(fila, "C") = h1.Cells(fila, "C") + cantidad
                Case "dev"
                    cantidad = h3.Cells(i, "F") * -1
                    h1.Cells(fila, "D") = h1.Cells(fila, "D") + cantidad
            End Select
            h1.Cells(fila, "E").FormulaR1C1 = "=RC[-4]+RC[-3]-RC[-2]-RC[-1]"
            h1.Cells(fila, "G").FormulaR1C1 = "=RC[-1]*RC[-2]"
        End If
    Next
    '
    Application.ScreenUpdating = True
End Sub

'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas