Como buscar artículos de un inventario en excel usando vba

Como hago para buscar un articulo con un criterio de búsqueda usando un userform de tal manera que todos los datos que rellene en una ficha de movimientos de artículos en una planilla de inventario en excel me estire todos sus movimientos de entradas, salidas, devoluciones, saldos inicial, si me podrías ayudar desde ya

3 Respuestas

Respuesta
2

Te anexo la macro para consultar un artículo o todos los artículos

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 CheckBox1 = False Then
        Call UnArticulo(h1, h2)
    Else
        Call Todos(h1, h2)
    End If
End Sub
'
Sub Todos(h1, h2)
'Por.Dante Amor
    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
    '
    'Poner datos:
    h1.[B3] = "Todos"
    h1.[D3] = "Todos"
    h1.[B5] = fecini
    h1.[D5] = fecfin
    '
    fila = 9
    For Each h3 In Sheets
        If h3.[B13] = "FECHA" Then
            u3 = h3.Range("B" & Rows.Count).End(xlUp).Row
            If u3 > 13 Then
                h1.Cells(fila, "A") = h3.Cells(14, "L")
                h1.Cells(fila, "F") = h3.Cells(u3, "M")
                nombre = h3.Name
                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
                fila = fila + 1
            End If
        End If
    Next
    Application.ScreenUpdating = True
End Sub
'
Sub UnArticulo(h1, h2)
'Por.Dante Amor
    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

sal u dos

Respuesta
1

este ejemplo http://www.programarexcel.com/2015/01/formulario-ingreso-y-egreso-de-stock.html?m=1 

https://youtu.be/gqZzSfikEYY 

Ahí vereas una explicación del funcionamiento del ejemplo por si te aporta algo más a lo que necesitas

Respuesta
1

[email protected] este mi correo

Es un infrome que require por articulo

¿Toda la informacion estas en una sola hoja o varias?

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas