Está en la página 1de 9

Sub Macro5()

Dim criterio As Variant


Dim rango3 As Range
Dim rango4 As Variant

criterio = "CALLAO"
Set rango3 = Sheets("Reporte").Range("B1:BE1")
Set rango4 = Sheets("Reporte").Range("B2885:BE2885")

' ActiveSheet.Cells(12, 2).Select


' Selection.FormulaArray = _
"=SUM(IF(rango3=""CALLAO"",rango4))"

ActiveSheet.Cells(12, 2) = Application.WorksheetFunction.SumIf(rango3,
criterio, rango4)

Sub Macro5()

Dim criterio As Variant


Dim rango3 As Range
Dim rango4 As Variant

'criterio = "CALLAO"
Set rango3 = Sheets("Reporte").Range("B1:BE1")
Set rango4 = Sheets("Reporte").Range("B2885:BE2885")

ActiveSheet.Cells(12, 2) = Application.WorksheetFunction.SumIf(rango3,
"CALLAO", rango4)
ActiveSheet.Cells(12, 3) = Application.WorksheetFunction.SumIf(rango3,
"LIMA CENTRO", rango4)
ActiveSheet.Cells(12, 4) = Application.WorksheetFunction.SumIf(rango3,
"LIMA MODERNA", rango4)
ActiveSheet.Cells(12, 5) = Application.WorksheetFunction.SumIf(rango3,
"LIMA NORTE", rango4)
ActiveSheet.Cells(12, 6) = Application.WorksheetFunction.SumIf(rango3,
"LIMA ESTE", rango4)
ActiveSheet.Cells(12, 7) = Application.WorksheetFunction.SumIf(rango3,
"LIMA SUR", rango4)
ActiveSheet.Cells(12, 8) = Application.WorksheetFunction.SumIf(rango3,
"PLAYAS", rango4)

End Sub

For m = mes To 12
If m = 1 Then cMes = "Enero"
If m = 2 Then cMes = "Febrero"
If m = 3 Then cMes = "Marzo"
If m = 4 Then cMes = "Abril"
If m = 5 Then cMes = "Mayo"
If m = 6 Then cMes = "Junio"
If m = 7 Then cMes = "Julio"
If m = 8 Then cMes = "Agosto"
If m = 9 Then cMes = "Setiembre"
If m = 10 Then cMes = "Octubre"
If m = 11 Then cMes = "Noviembre"
If m = 12 Then cMes = "Diciembre"
If m < 10 Then
Diames = "01/0" & m & "/" & nAnio
nMes = "0" & Trim(Str(m))
Else
Diames = "01/" & m & "/" & nAnio
nMes = Trim(Str(m))
End If

Des_distrito
Des_producto

Sub Macro3()
'
' Macro3 Macro
'
'
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=
_
"Hoja1!R1C1:R31637C22",
Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Hoja4!R3C1", TableName:="Tabla dinmica5", _
DefaultVersion:=xlPivotTableVersion14
Sheets("Hoja4").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("Tabla dinmica5").PivotFields("des_distrito")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("Tabla dinmica5").AddDataField
ActiveSheet.PivotTables _
("Tabla dinmica5").PivotFields("des_producto"), "Cuenta de
des_producto", _
xlCount
Windows("prueba macros 2.0.xlsm").Activate
ActiveCell.FormulaR1C1 = _
"=HLOOKUP(R[-2884]C,'[PDE COMERCIO 01-01-15.xlsx]Hoja4'!
R4:R5,2,FALSE)"
End Sub

Sub Macro4()
Dim rango1 As Range
Dim rango2 As Variant
Dim criterio As Variant
Set rango1 = Range("C7:E7")
Set rango2 = Range("C8:E8")
'Set criterio = Range("C7")
criterio = "sabado"
'ActiveSheet.Cells(1, 1) =
Application.WorksheetFunction.SumIf(Range("C7:E7"), Range("C7"),
Range("C8:E8"))
ActiveSheet.Cells(10, 1) = Application.WorksheetFunction.SumIf(rango1,
criterio, rango2)
End Sub
Sub Macro5()
Dim criterio As Variant
Dim rango3 As Range
Dim rango4 As Variant
'criterio = "CALLAO"
Set rango3 = Sheets("Reporte").Range("B1:BE1")
Set rango4 = Sheets("Reporte").Range("B2885:BE2885")
ActiveSheet.Cells(12, 2) =
"CALLAO", rango4)
ActiveSheet.Cells(12, 3) =
"LIMA CENTRO", rango4)
ActiveSheet.Cells(12, 4) =
"LIMA MODERNA", rango4)
ActiveSheet.Cells(12, 5) =
"LIMA NORTE", rango4)
ActiveSheet.Cells(12, 6) =
"LIMA ESTE", rango4)
ActiveSheet.Cells(12, 7) =
"LIMA SUR", rango4)
ActiveSheet.Cells(12, 8) =
"PLAYAS", rango4)

Application.WorksheetFunction.SumIf(rango3,
Application.WorksheetFunction.SumIf(rango3,
Application.WorksheetFunction.SumIf(rango3,
Application.WorksheetFunction.SumIf(rango3,
Application.WorksheetFunction.SumIf(rango3,
Application.WorksheetFunction.SumIf(rango3,
Application.WorksheetFunction.SumIf(rango3,

End Sub
Sub macros6()
Mes = "ENERO"
Ao = 2015
DIA = 1
tAo = Mid(Ao, 3, 2)
If
If
If
If
If
If
If
If
If
If
If
If

Mes
Mes
Mes
Mes
Mes
Mes
Mes
Mes
Mes
Mes
Mes
Mes

=
=
=
=
=
=
=
=
=
=
=
=

"ENERO" Then m = 1
"FEBRERO" Then m = 2
"MARZO" Then m = 3
"ABRIL" Then m = 4
"MAYO" Then m = 5
"JUNIO" Then m = 6
"JULIO" Then m = 7
"AGOSTO" Then m = 8
"SEPTIEMBRE" Then m = 9
"OCTUBRE" Then m = 10
"NOVIEMBRE" Then m = 11
"DICIEMBRE" Then m = 12

If m < 10 Then
m = "0" & m '<---- m es = a Mes con un cero a la izquierda si es menor a 10
End If
If DIA < 10 Then
DIA = "0" & DIA
End If
Dim Archivo As String
Dim wb As Workbook
'Fecha = "01-01-15"
'Archivo = "Z:\PLANTA SUR\2015\junio\VENTA COMERCIO SUR (junio) 2015.xlsx"
Archivo = "G:\el comercio pde\" & Ao & "\" & Mes & " " & Ao & "\PDE
COMERCIO" & " " & DIA & "-" & m & "-" & tAo & ".xlsx"
Set wb = Workbooks.Open(Archivo)
Call macro
End Sub
Sub Tabladinamica()
ActiveWorkbook.Sheets.Add

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=
_
"Hoja1!R1C1:R31637C22",
Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Hoja4!R3C1", TableName:="Tabla dinmica5", _
DefaultVersion:=xlPivotTableVersion14
Sheets("Hoja4").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("Tabla dinmica5").PivotFields("des_distrito")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("Tabla dinmica5").AddDataField
ActiveSheet.PivotTables _
("Tabla dinmica5").PivotFields("des_producto"), "Cuenta de
des_producto", _
xlCount
Windows("prueba macros 2.0.xlsm").Activate
ActiveCell.FormulaR1C1 = _
"=HLOOKUP(R[-2884]C,'[PDE COMERCIO" & " " & DIA & "-" & m & "-" &
tAo & ".xlsx]Hoja4'!R4:R5,2,FALSE)"
End Sub
Sub macro()
' Macro3 Macro
'
Mes = "ENERO"
Ao = 2015
DIA = 1
tAo = Mid(Ao, 3, 2)
If
If
If
If
If
If
If
If
If
If
If
If

Mes
Mes
Mes
Mes
Mes
Mes
Mes
Mes
Mes
Mes
Mes
Mes

=
=
=
=
=
=
=
=
=
=
=
=

"ENERO" Then m = 1
"FEBRERO" Then m = 2
"MARZO" Then m = 3
"ABRIL" Then m = 4
"MAYO" Then m = 5
"JUNIO" Then m = 6
"JULIO" Then m = 7
"AGOSTO" Then m = 8
"SEPTIEMBRE" Then m = 9
"OCTUBRE" Then m = 10
"NOVIEMBRE" Then m = 11
"DICIEMBRE" Then m = 12

If m < 10 Then
m = "0" & m '<---- m es = a Mes con un cero a la izquierda si es menor a 10
End If

If DIA < 10 Then


DIA = "0" & DIA
End If
'
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=
_
"Hoja1!R1C1:R31637C22",
Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Hoja4!R3C1", TableName:="Tabla dinmica5", _
DefaultVersion:=xlPivotTableVersion14
Sheets("Hoja4").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("Tabla dinmica5").PivotFields("des_distrito")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("Tabla dinmica5").AddDataField
ActiveSheet.PivotTables _
("Tabla dinmica5").PivotFields("des_producto"), "Cuenta de
des_producto", _
xlCount
' Windows("prueba macros 2.0.xlsm").Activate
Application.Workbooks("prueba macros
2.0.xlsm").Worksheets("Reporte").Activate '<---- libro destino de los datos de
tabla dinamica
'ActiveCell.FormulaR1C1 = _
"=HLOOKUP(R[-2884]C,'[PDE COMERCIO 01-01-15.xlsx]Hoja4'!
R4:R5,2,FALSE)"
ActiveSheet.Cells(2886, 2) = _
"=HLOOKUP(R[-2884]C,'[PDE COMERCIO" & " " & DIA & "-" & m & "-" &
tAo & ".xlsx]Hoja4'!R4:R5,2,FALSE)" '<---- celda destino de los datos de tabla
dinamica
End Sub