[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

Excel: Pivot Macro Help

Asked by netcmh in Microsoft Excel Spreadsheet Software, Visual Basic v1.0.5.x

Hello,

I have this subroutine that grabs data from a sheet and pivots it into a more useful format.

It works great if I have 7 to 10 columns to play with, but if that number hits 30 plus, I'm running into that 256 column limit - excel 03.

Is there a way that during this pivot, a macro scans for column values, and if the sum of those values is zero, delete that column. That'll free up some columns for the rest of my data.

I don't have a workbook that I can upload. Sorry.

Thank you in advance.
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:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
Sub ConsolidateData()
 
Application.DisplayAlerts = False
AlertBeforeOverwriting = False
Application.ScreenUpdating = False
 
    Workbooks.Open Filename:="C:\data.xls"
    Dim wb As Workbook, ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet, rng As Range, pt As PivotTable
    Dim fld1 As String, fld2 As String, fld3 As String, fld4 As String
    
    Set wb = ActiveWorkbook
    Set ws1 = ActiveSheet
    
    ' Add the header row needed for the PivotTable
    If ws1.[A1] <> "Device" Then
    ws1.Rows(1).Insert
    ws1.[A1].Resize(1, 34) = Array("Device", "Date", "Fa0transmitUsage", "Fa0RecieveUsage", "Fa02transmitUsage", "Fa02RecieveUsage", "Fa00transmitUsage", "Fa00RecieveUsage", "Fa002transmitUsage", "Fa002RecieveUsage", "Fa000transmitUsage", "Fa000RecieveUsage", "Fa0002transmitUsage", "Fa0002RecieveUsage", "Fa0000transmitUsage", "Fa0000RecieveUsage", "Fa0010transmitUsage", "Fa0010RecieveUsage", "Fa001transmitUsage", "Fa001RecieveUsage", "Fa0012transmitUsage", "Fa0012RecieveUsage", "Fa01transmitUsage", "Fa01RecieveUsage", "Fa012transmitUsage", "Fa012RecieveUsage", "Fa0100transmitUsage", "Fa0100RecieveUsage", "Fa0110transmitUsage", "Fa0110RecieveUsage", "Fa1transmitUsage", "Fa1RecieveUsage", "Fa12transmitUsage", "Fa12RecieveUsage")
    End If
 
    fld1 = ws1.[C1].value
    fld2 = ws1.[D1].value
    fld3 = ws1.[E1].value
    fld4 = ws1.[F1].value
    fld5 = ws1.[G1].value
    fld6 = ws1.[H1].value
    fld7 = ws1.[I1].value
    fld8 = ws1.[J1].value
    fld9 = ws1.[K1].value
    fld10 = ws1.[L1].value
    fld11 = ws1.[M1].value
    fld12 = ws1.[N1].value
    fld13 = ws1.[O1].value
    fld14 = ws1.[P1].value
    fld15 = ws1.[Q1].value
    fld16 = ws1.[R1].value
    fld17 = ws1.[S1].value
    fld18 = ws1.[T1].value
    fld19 = ws1.[U1].value
    fld20 = ws1.[V1].value
    fld21 = ws1.[W1].value
    fld22 = ws1.[X1].value
    fld23 = ws1.[Y1].value
    fld24 = ws1.[Z1].value
    fld25 = ws1.[AA1].value
    fld26 = ws1.[AB1].value
    fld27 = ws1.[AC1].value
    fld28 = ws1.[AD1].value
    fld29 = ws1.[AE1].value
    fld30 = ws1.[AF1].value
    fld31 = ws1.[AG1].value
    fld32 = ws1.[AH1].value
    
    Set rng = ws1.[A1].CurrentRegion
    
    wb.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        ws1.Name & "!" & rng.Address(xlR1C1)).CreatePivotTable TableDestination:=""
        
    Set ws2 = ActiveSheet
    ws2.PivotTableWizard TableDestination:=ws2.Cells(3, 1)
    
    Set pt = ws2.PivotTables(1)
    pt.AddFields RowFields:=Array("Date", "Data"), ColumnFields:="Device"
    
    With pt.PivotFields(fld1)
        .Orientation = xlDataField
        .Position = 1
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld2)
        .Orientation = xlDataField
        .Position = 2
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld3)
        .Orientation = xlDataField
        .Position = 3
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld4)
        .Orientation = xlDataField
        .Position = 4
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld5)
        .Orientation = xlDataField
        .Position = 5
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld6)
        .Orientation = xlDataField
        .Position = 6
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld7)
        .Orientation = xlDataField
        .Position = 7
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld8)
        .Orientation = xlDataField
        .Position = 8
        '.Function = xlSum
    End With
    
        With pt.PivotFields(fld9)
        .Orientation = xlDataField
        .Position = 9
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld10)
        .Orientation = xlDataField
        .Position = 10
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld11)
        .Orientation = xlDataField
        .Position = 11
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld12)
        .Orientation = xlDataField
        .Position = 12
        '.Function = xlSum
    End With
    
        With pt.PivotFields(fld13)
        .Orientation = xlDataField
        .Position = 13
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld14)
        .Orientation = xlDataField
        .Position = 14
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld15)
        .Orientation = xlDataField
        .Position = 15
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld16)
        .Orientation = xlDataField
        .Position = 16
        '.Function = xlSum
    End With
    
        With pt.PivotFields(fld17)
        .Orientation = xlDataField
        .Position = 17
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld18)
        .Orientation = xlDataField
        .Position = 18
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld19)
        .Orientation = xlDataField
        .Position = 19
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld20)
        .Orientation = xlDataField
        .Position = 20
        '.Function = xlSum
    End With
    
        With pt.PivotFields(fld21)
        .Orientation = xlDataField
        .Position = 21
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld22)
        .Orientation = xlDataField
        .Position = 22
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld23)
        .Orientation = xlDataField
        .Position = 23
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld24)
        .Orientation = xlDataField
        .Position = 24
        '.Function = xlSum
    End With
    
        With pt.PivotFields(fld25)
        .Orientation = xlDataField
        .Position = 25
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld26)
        .Orientation = xlDataField
        .Position = 26
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld27)
        .Orientation = xlDataField
        .Position = 27
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld28)
        .Orientation = xlDataField
        .Position = 28
        '.Function = xlSum
    End With
    
        With pt.PivotFields(fld29)
        .Orientation = xlDataField
        .Position = 29
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld30)
        .Orientation = xlDataField
        .Position = 30
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld31)
        .Orientation = xlDataField
        .Position = 31
        '.Function = xlSum
    End With
    
    With pt.PivotFields(fld32)
        .Orientation = xlDataField
        .Position = 32
        '.Function = xlSum
    End With
        
    With pt.DataPivotField
        .Orientation = xlColumnField
        .Position = 2
    End With
    
    With pt
        .ColumnGrand = False
        .RowGrand = False
    End With
    
    pt.PivotFields("Sum of " & fld1).Caption = fld1 & " "
    pt.PivotFields("Sum of " & fld2).Caption = fld2 & " "
    pt.PivotFields("Sum of " & fld3).Caption = fld3 & " "
    pt.PivotFields("Sum of " & fld4).Caption = fld4 & " "
    pt.PivotFields("Sum of " & fld5).Caption = fld5 & " "
    pt.PivotFields("Sum of " & fld6).Caption = fld6 & " "
    pt.PivotFields("Sum of " & fld7).Caption = fld7 & " "
    pt.PivotFields("Sum of " & fld8).Caption = fld8 & " "
    pt.PivotFields("Sum of " & fld9).Caption = fld9 & " "
    pt.PivotFields("Sum of " & fld10).Caption = fld10 & " "
    pt.PivotFields("Sum of " & fld11).Caption = fld11 & " "
    pt.PivotFields("Sum of " & fld12).Caption = fld12 & " "
    pt.PivotFields("Sum of " & fld13).Caption = fld13 & " "
    pt.PivotFields("Sum of " & fld14).Caption = fld14 & " "
    pt.PivotFields("Sum of " & fld15).Caption = fld15 & " "
    pt.PivotFields("Sum of " & fld16).Caption = fld16 & " "
    pt.PivotFields("Sum of " & fld17).Caption = fld17 & " "
    pt.PivotFields("Sum of " & fld18).Caption = fld18 & " "
    pt.PivotFields("Sum of " & fld19).Caption = fld19 & " "
    pt.PivotFields("Sum of " & fld20).Caption = fld20 & " "
    pt.PivotFields("Sum of " & fld21).Caption = fld21 & " "
    pt.PivotFields("Sum of " & fld22).Caption = fld22 & " "
    pt.PivotFields("Sum of " & fld23).Caption = fld23 & " "
    pt.PivotFields("Sum of " & fld24).Caption = fld24 & " "
    pt.PivotFields("Sum of " & fld25).Caption = fld25 & " "
    pt.PivotFields("Sum of " & fld26).Caption = fld26 & " "
    pt.PivotFields("Sum of " & fld27).Caption = fld27 & " "
    pt.PivotFields("Sum of " & fld28).Caption = fld28 & " "
    pt.PivotFields("Sum of " & fld29).Caption = fld29 & " "
    pt.PivotFields("Sum of " & fld30).Caption = fld30 & " "
    pt.PivotFields("Sum of " & fld31).Caption = fld31 & " "
    pt.PivotFields("Sum of " & fld32).Caption = fld32 & " "
   
    pt.TableRange1.CurrentRegion.Copy
    
    Worksheets.Add
    Set ws3 = ActiveSheet
    
    ws3.[A1].PasteSpecial Paste:=xlPasteValues, Operation:=xlNone
    ws3.[A1].PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone
    
    ws3.Columns("A").EntireColumn.AutoFit
    ws3.Rows(1).Delete
    
    'Delete the added header row
    'ws1.Rows(1).Delete
    
    Application.DisplayAlerts = False
    ws2.Delete
    Application.DisplayAlerts = True
    
    Application.ScreenUpdating = True
    Application.GoTo ws3.[A1]
    
    ActiveWorkbook.Names.Add Name:="Database", RefersToR1C1:= _
       "=OFFSET(Sheet2!R1C1,0,0,COUNTA(Sheet2!C1)+1,105)"
   
End Sub
[+][-]10/22/09 11:04 AM, ID: 25637205Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/22/09 11:51 AM, ID: 25637631Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10/22/09 12:32 PM, ID: 25638059Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/22/09 02:06 PM, ID: 25639039Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Microsoft Excel Spreadsheet Software, Visual Basic v1.0.5.x
Sign Up Now!
Solution Provided By: folderol
Participating Experts: 2
Solution Grade: B
 
[+][-]10/22/09 02:15 PM, ID: 25639124Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/22/09 02:18 PM, ID: 25639152Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 11:37 AM, ID: 25762359Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625