Como trasladar calculos de stock usando un listbox en excel vba

Tengo un listbox donde yo ingreso los datos de entradas, salidas, devoluciones, etc de un registro de inventario, lo que quisiera saber como hago como para que me copie a una celda todos los datos que ingreso al listbox y quede como un informe, esto a fin de poder imprimir el reporte.

1 respuesta

Respuesta
2

Te anexo el código para los cálculos

            h1.Cells(fila, "E").FormulaR1C1 = "=RC[-4]+RC[-3]-RC[-2]-RC[-1]"
            h1.Cells(fila, "G").FormulaR1C1 = "=RC[-1]*RC[-2]"

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