Esta es la macro para el consumo de clientes
Private Sub CommandButton1_Click() 'consumo clientes
'Por.Dante Amor
Dim fec1 As Date
Dim fec2 As Date
'
Application.ScreenUpdating = False
u = Hoja12.Range("A" & Rows.Count).End(xlUp).Row
If u < 3 Then u = 3
uc = Hoja12.Cells(1, Columns.Count).End(xlToLeft).Column + 1
Hoja12.Range(Hoja12.Cells(2, "A"), Hoja12.Cells(u, uc)).ClearContents
Hoja12.Range(Hoja12.Cells(1, "C"), Hoja12.Cells(1, uc)).ClearContents
'
[G1] = DTPicker1
[G2] = DTPicker2
'
For i = 2 To Hoja4.Range("A" & Rows.Count).End(xlUp).Row
'
If Hoja4.Cells(i, "B") >= [G1] And _
Hoja4.Cells(i, "B") <= [G2] Then
'busca código
Set b = Hoja12.Range("A:A").Find(Hoja4.Cells(i, "A"), LookAt:=xlWhole)
If Not b Is Nothing Then
fil = b.Row
'busca cliente
col = BuscarCliente(i)
Hoja12.Cells(fil, col) = Hoja12.Cells(fil, col) + Hoja4.Cells(i, "D")
Else
'busca descripción
Set d = Hoja1.Range("A:A").Find(Hoja4.Cells(i, "A"), LookAt:=xlWhole)
If Not d Is Nothing Then desc = Hoja1.Cells(d.Row, "B") Else desc = ""
'
u = Hoja12.Range("A" & Rows.Count).End(xlUp).Row + 1
'busca cliente
col = BuscarCliente(i)
Hoja12.Cells(u, "A") = Hoja4.Cells(i, "A")
Hoja12.Cells(u, "B") = desc
Hoja12.Cells(1, col) = Hoja4.Cells(i, "C")
Hoja12.Cells(u, col) = Hoja4.Cells(i, "D")
End If
End If
Next
'
[G1:G2] = ""
Hoja12.Select
Application.ScreenUpdating = True
MsgBox "Informe Mensual Terminado", vbInformation
End
End Sub
Function BuscarCliente(i)
'Por.Dante Amor
Set c = Hoja12.Rows(1).Find(Hoja4.Cells(i, "C"), LookAt:=xlWhole)
If Not c Is Nothing Then
BuscarCliente = c.Column
Else
BuscarCliente = Hoja12.Cells(1, Columns.Count).End(xlToLeft).Column + 1
End If
End Function