LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Pivot table consolidation with variable number of worksheets

I have a variable number of worksheets for which I’d like to automate
a pivot table consolidation routine.

I’ve tried the code below not to avail. The source keeps being only on
sheet4, while for my test, it should pickup sheet2 through sheet5.

Any thoughts?


Sub test()
Application.ScreenUpdating = False
Dim wsn As String
Dim i As Integer
Dim prange As String
Dim PCrange As String
Dim rangearr() As String

ReDim Preserve rangearr(i To Worksheets.Count - 5)

For i = 2 To Worksheets.Count - 3 Step 1
wsn = Worksheets(i).Name
Sheets(wsn).Select
prange = Range(Range("A1"), Range("A1").End(xlDown).Offset(0,
1)).Address(ReferenceStyle:=xlR1C1, _
RowAbsolute:=True, _
ColumnAbsolute:=True)
PCrange = wsn & "!" & prange
If (i - 3) < 0 Then rangearr(0) = PCrange _
Else: rangearr(LBound(rangearr) + (i - 2)) = PCrange
Next i

Sheets("sheet1").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlConso lidation,
SourceData:= _
rangearr).CreatePivotTable TableDestination:=Range("a1"), _
TableName:="PivotTable1"
With ActiveSheet.PivotTables("PivotTable1")
..ColumnGrand = False
..HasAutoFormat = False
..RowGrand = False
..SmallGrid = False
End With
ActiveSheet.PivotTables("PivotTable1").SmallGrid = False
ActiveSheet.PivotTables("PivotTable1").PivotFields ("Data").PivotItems
( _
"Sum of Value").Position = 1

Application.CommandBars("PivotTable").Visible = False

End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot table - consolidation report Barb Reinhardt Excel Programming 1 October 14th 08 08:57 AM
Pivot table - consolidation range Igor[_2_] Excel Programming 0 October 12th 08 09:55 AM
Pivot table consolidation Ariella Excel Discussion (Misc queries) 1 July 29th 08 05:15 PM
Pivot Table-Multiple Consolidation Ranges Rach Excel Discussion (Misc queries) 3 January 12th 07 12:46 AM
Pivot Table - Multiple consolidation Range tengreen Excel Worksheet Functions 1 July 1st 05 07:18 PM


All times are GMT +1. The time now is 04:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"