Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.scripting.vbscript
external usenet poster
 
Posts: 26
Default Dynamic Array as pivot table SourceData..?

Hi,

As far as I know, the SourceData for a Pivot Table can be an array of
ranges, but it's not working for me. The following code creates a dynamic
array of ranges, which is then supplied to the SourceData parameter of the
PivotTableWizard. This causes an error "Pivot Table Wizard method of
Worksheet class failed".

----------------------------------------------------------------------------
-----

im i As Integer
Dim m As Integer
Dim pivotTableRangeArray() As Range
Dim dataSheetNames() As String
Dim re As New RegExp

' Populate an array of data sheet names
re.IgnoreCase = True
re.Pattern = "[a-z]\.[a-z\_]"
m = 1
For i = 1 To ActiveWorkbook.Sheets.Count
If re.Test(Sheets(i).Name) Then
ReDim Preserve dataSheetNames(1 To m)
dataSheetNames(m) = Sheets(i).Name
'Debug.Print "Sheet:", i, m, dataSheetNames(m)
m = m + 1
End If
Next i
Set re = Nothing

' Populate an array of ranges for the pivot table
For i = 1 To UBound(dataSheetNames)
' populate the pivotTableRangeArray
ReDim Preserve pivotTableRangeArray(1 To i)
Set pivotTableRangeArray(i) =
Sheets(dataSheetNames(i)).Range("A1").CurrentRegio n
'Debug.Print i, UBound(pivotTableRangeArray)
Next i

' Create the pivot table - use the
With ActiveSheet
.PivotTableWizard SourceType:=xlDataBase, _
SourceData:=pivotTableRangeArray, _
TableName:="sdc.vsim_c", _
TableDestination:=.Range("A65536").End(xlUp).Offse t(2, 0)
End With

----------------------------------------------------------------------------
------

Can anyone shed any light on this?

Thank you very much,

Robert Stober


Reply
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
Dynamic pivot table linked to dynamic excel spreadsheets FErd Excel Worksheet Functions 0 April 29th 10 10:44 PM
Pivot table from dynamic refreshed pivot table Michael.Tarnowski Excel Worksheet Functions 1 January 21st 09 01:57 AM
Dynamic sourcedata when copying chart within sheet [email protected] Charts and Charting in Excel 3 June 11th 08 03:37 PM
Pivot table with a variable range in the sourcedata field [email protected] Excel Discussion (Misc queries) 2 January 31st 07 12:11 AM
Dynamic table array using Hyperlink Salman Excel Worksheet Functions 4 January 6th 07 06:23 AM


All times are GMT +1. The time now is 11:50 PM.

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

About Us

"It's about Microsoft Excel"