Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default PivotTableWizard SourceData question

Hi all,

In the VBA online help it says that the SourceData property accepts "an
array of ranges". If this is true, may anyone advise why the following code
failed? Thanks.

Sub CreatePivot()
Dim MonthlyData(1 To 12) As Range
Dim i As Integer

For i = 1 To 12
Set MonthlyData(i) = Worksheets(i).Range("A1").CurrentRegion
Next

ActiveSheet.PivotTableWizard _
SourceType:=xlDatabase, _
SourceData:=MonthlyData, _
tablename:="YearlySales"

End Sub

Frederick Chow
Hong Kong.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default PivotTableWizard SourceData question

Frederick

The help lies. It says "array of ranges" but it should say "array of
strings that are valid external cell addresses". You need to change your
SourceType to xlConsolidation and change your loop to

Dim MonthlyData(1 to 12) as String

For i = 1 to 12
MonthlyData(i) =
Worksheets(i).Range("A1").CurrentRegion.Address(Tr ue,True,xlR1C1,True)
Next i

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Microsoft Forum wrote:
Hi all,

In the VBA online help it says that the SourceData property accepts
"an array of ranges". If this is true, may anyone advise why the
following code failed? Thanks.

Sub CreatePivot()
Dim MonthlyData(1 To 12) As Range
Dim i As Integer

For i = 1 To 12
Set MonthlyData(i) = Worksheets(i).Range("A1").CurrentRegion
Next

ActiveSheet.PivotTableWizard _
SourceType:=xlDatabase, _
SourceData:=MonthlyData, _
tablename:="YearlySales"

End Sub

Frederick Chow
Hong Kong.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default PivotTableWizard SourceData question

Hi Dick,

Thanks for your response, and I modifed my macro as advised but the macro
still failed at the PivotTableWizard method. May you give me futher adivce?

Sub CreatePivot()
Dim MonthlyData(1 To 12) As String
Dim i As Integer

For i = 1 To 12
MonthlyData(i) = Worksheets(i).Range("A1").CurrentRegion.Address _
(True, True, xlR1C1, True)
Next

ActiveSheet.PivotTableWizard _
SourceType:=xlDatabase, _
SourceData:=MonthlyData, _
tablename:="YearlySales"

End Sub

Frederick Chow

"Dick Kusleika" wrote in message
...
Frederick

The help lies. It says "array of ranges" but it should say "array of
strings that are valid external cell addresses". You need to change your
SourceType to xlConsolidation and change your loop to

Dim MonthlyData(1 to 12) as String

For i = 1 to 12
MonthlyData(i) =
Worksheets(i).Range("A1").CurrentRegion.Address(Tr ue,True,xlR1C1,True)
Next i

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Microsoft Forum wrote:
Hi all,

In the VBA online help it says that the SourceData property accepts
"an array of ranges". If this is true, may anyone advise why the
following code failed? Thanks.

Sub CreatePivot()
Dim MonthlyData(1 To 12) As Range
Dim i As Integer

For i = 1 To 12
Set MonthlyData(i) = Worksheets(i).Range("A1").CurrentRegion
Next

ActiveSheet.PivotTableWizard _
SourceType:=xlDatabase, _
SourceData:=MonthlyData, _
tablename:="YearlySales"

End Sub

Frederick Chow
Hong Kong.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default PivotTableWizard SourceData question

Frederick

Change this

SourceType:=xlDatabase, _


to this

SourceType:=xlConsolidation, _

If that doesn't fix it, be sure to include the error message when you post
back.

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com


Microsoft Forum wrote:
Hi Dick,

Thanks for your response, and I modifed my macro as advised but the
macro still failed at the PivotTableWizard method. May you give me
futher adivce?
Sub CreatePivot()
Dim MonthlyData(1 To 12) As String
Dim i As Integer

For i = 1 To 12
MonthlyData(i) = Worksheets(i).Range("A1").CurrentRegion.Address _
(True, True, xlR1C1, True)
Next

ActiveSheet.PivotTableWizard _
SourceType:=xlDatabase, _
SourceData:=MonthlyData, _
tablename:="YearlySales"

End Sub

Frederick Chow

"Dick Kusleika" wrote in message
...
Frederick

The help lies. It says "array of ranges" but it should say "array of
strings that are valid external cell addresses". You need to change
your SourceType to xlConsolidation and change your loop to

Dim MonthlyData(1 to 12) as String

For i = 1 to 12
MonthlyData(i) =
Worksheets(i).Range("A1").CurrentRegion.Address(Tr ue,True,xlR1C1,True)
Next i

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Microsoft Forum wrote:
Hi all,

In the VBA online help it says that the SourceData property accepts
"an array of ranges". If this is true, may anyone advise why the
following code failed? Thanks.

Sub CreatePivot()
Dim MonthlyData(1 To 12) As Range
Dim i As Integer

For i = 1 To 12
Set MonthlyData(i) = Worksheets(i).Range("A1").CurrentRegion
Next

ActiveSheet.PivotTableWizard _
SourceType:=xlDatabase, _
SourceData:=MonthlyData, _
tablename:="YearlySales"

End Sub

Frederick Chow
Hong Kong.



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
PivotTableWizard help with VB circuit_breaker Excel Worksheet Functions 1 July 7th 09 02:08 PM
Dynamic sourcedata when copying chart within sheet [email protected] Charts and Charting in Excel 3 June 11th 08 03:37 PM
SourceData in pivot table JIM.H.[_2_] Excel Programming 0 June 9th 04 12:59 AM
Change SourceData in Excel PivotTable via VBA CarlsonClan Excel Programming 1 April 9th 04 04:15 AM
Setting up a SourceData:= in VB Emmanuel[_2_] Excel Programming 1 January 22nd 04 08:15 PM


All times are GMT +1. The time now is 03:22 AM.

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"