Excel - Condicionar tabla dinámica con VBA

 
Vista:
sin imagen de perfil

Condicionar tabla dinámica con VBA

Publicado por Flor (1 intervención) el 28/02/2018 23:05:36
Buen día.

Quisiera crear una tabla dinámica a través de VBA que me sirve para diferentes libros de Excel
El origen de los datos de esta tabla dinámica se encuentra en otra tabla, cuando creo mi tabla dinámica no utilizo todas la columnas de la tabla de base datos, solo algunas en especifico, pero esas columnas no siempre contienen datos en los diferentes libros o están en 0.
Quisiera crear una condición en la que explique que si la columna 3 sus datos están en 0, no se considere dentro de la tabla dinámica, pero si tienes valores >= 0 si sea considerada.
Hasta ahora tengo la siguiente programación:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
Sub P2_CrearTablaDinamica_Sem()
 
' Eliminar Hoja (Si Existe)
On Error Resume Next
Worksheets("TablaDinamica").Delete
 
' Crear Hoja TablaDinamica
Worksheets.Add(Before:=ActiveSheet).Name = "TablaDinamica"
 
' Crear Pivot Cache
Set PCache = ActiveWorkbook.PivotCaches.Create( _
SourceType:=xlDatabase, SourceData:="Tabla1")
 
' Crear tabla dinámica
Set TDinamica = PCache.CreatePivotTable( _
TableDestination:="TablaDinamica!R5C1", TableName:="Tabla dinámica")
 
 
With TDinamica.PivotFields("NOMBRE PTA CC")
    .Orientation = xlRowField
    .Position = 1
End With
 
' Insertar Valores
With TDinamica.PivotFields("SUELDO2")
    .Orientation = xlDataField
    .Position = 1
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "SUELDOS"
End With
 
With TDinamica.PivotFields("HORAS EXTRAS")
    .Orientation = xlDataField
    .Position = 2
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "H.E"
End With
 
With TDinamica.PivotFields("PRIMA DOMINICAL")
    .Orientation = xlDataField
    .Position = 3
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "P.D."
End With
 
With TDinamica.PivotFields("VACACIONES2")
    .Orientation = xlDataField
    .Position = 4
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "VAC."
End With
 
With TDinamica.PivotFields("PRIMA VACACIONAL")
    .Orientation = xlDataField
    .Position = 5
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "P.VAC."
End With
 
With TDinamica.PivotFields("INCENTIVO PRODUCTIVIDAD")
    .Orientation = xlDataField
    .Position = 6
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "I.P."
End With
 
With TDinamica.PivotFields("RETROACTIVO2")
    .Orientation = xlDataField
    .Position = 7
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "RETRO"
End With
 
With TDinamica.PivotFields("Bono de Productividad")
    .Orientation = xlDataField
    .Position = 8
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "B.P"
End With
 
With TDinamica.PivotFields("BONO DE COMPENSACION")
    .Orientation = xlDataField
    .Position = 9
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "B.C"
End With
 
With TDinamica.PivotFields("GRATIFICACIONES")
    .Orientation = xlDataField
    .Position = 10
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "GRAT."
End With
 
With TDinamica.PivotFields("PREMIO DE PUNTUALIDAD")
    .Orientation = xlDataField
    .Position = 11
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "P.PUNT."
End With
 
With TDinamica.PivotFields("PREMIO DE ASISTENCIA")
    .Orientation = xlDataField
    .Position = 12
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "P.ASIST."
End With
 
With TDinamica.PivotFields("VALES DE DESPENSA")
    .Orientation = xlDataField
    .Position = 13
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "DESPENSA"
End With
 
With TDinamica.PivotFields("COMISIONES")
    .Orientation = xlDataField
    .Position = 14
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "COMISION"
End With
 
With TDinamica.PivotFields("DIA ADICIONAL")
    .Orientation = xlDataField
    .Position = 15
    .Fuction = xlSum
    .NumberFormat = "#,##0.00"
    .Name = "D.ADIC."
End With
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder