Totalizar ventas mensuales por promotor

Para Dante Amor

Se requiere macro que totalice las ventas por promotor de acuerdo al mes de venta

Se tiene dos archivos A.xlsx y B.xlsx donde:

A.xlsx

A                                          B        C                  D        E         ........

Id Promotor               Enero       Febrero    Marzo    Abril     ....... Diciembre

1

2

n registros

B.xlsx

A                                          B                                C       

Id Promotor               FECHA VENTA            VALOR VENTA

1                                     18/01/2017                   10

2                                     10/01/2017                   20

1                                      19/01/2017                   10

4                                      18/03/2017                 40

k registros

RESULTADO EN:

A.xlsx

A                                          B       C                D           E .......

Id Promotor               Enero      Febrero   Marzo   Abril     ....... Diciembre

1                                     20

2                                     20

4                                                                        40

TOTAL                            40              0              40

2 respuestas

Respuesta
2

Te anexo la macro, los 2 libros deberán estar abiertos.

Sub Totalizar_Ventas()
'Por.Dante Amor
    Set l1 = ThisWorkbook   'promotores
    Set l2 = Workbooks("Ventas.xlsx")   'ventas
    Set h1 = l1.Sheets(1)
    Set h2 = l2.Sheets(1)
    '
    u = h1.Range("A" & Rows.Count).End(xlUp).Row - 1
    h1.Range("B2:M" & u).ClearContents
    Set r = h2.Columns("A")
    For i = 2 To u
        Set b = r.Find(h1.Cells(i, "A"), lookat:=xlWhole)
        If Not b Is Nothing Then
            celda = b.Address
            Do
                mes = Month(h2.Cells(b.Row, "B")) + 1
                h1.Cells(i, mes) = h1.Cells(i, mes) + h2.Cells(b.Row, "C")
                Set b = r.FindNext(b)
            Loop While Not b Is Nothing And b.Address <> celda
        End If
    Next
    MsgBox "Ventas actualizadas"
End Sub

.

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

.

Avísame cualquier duda

.

Respuesta
-1

Hasta tanto tengas una respuesta quizás te interese revisar estos ejemplos que te podrían orientar mientras tanto

https://youtu.be/TOXRk5oWLW4

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas