#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'" & Activehseet.Name & "'!R21C2:R65536C8").CreatePivotTable
TableDestination:="", _TableName:="PivotTable2"

Error: Argument not optional.

I think this comes from the last section of the above TableDestination:=""

Help


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Macro

1) Split the one-liner into several separate bits, and check where the error
occurs
2) Spend a few minutes reading the Excel VBA manual

/MP

"Nbiggss" wrote:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'" & Activehseet.Name & "'!R21C2:R65536C8").CreatePivotTable
TableDestination:="", _TableName:="PivotTable2"

Error: Argument not optional.

I think this comes from the last section of the above TableDestination:=""

Help


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Macro

Yes, I believe TableDestination is a required argument. So why not supply
one.

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, _
SourceData:="'" & Activehseet.Name & "'!R21C2:R65536C8") _
.CreatePivotTable TableDestination:=Activesheet.Range("M1"), _
TableName:="PivotTable2"

--
Regards,
Tom Ogilvy



"Nbiggss" wrote:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'" & Activehseet.Name & "'!R21C2:R65536C8").CreatePivotTable
TableDestination:="", _TableName:="PivotTable2"

Error: Argument not optional.

I think this comes from the last section of the above TableDestination:=""

Help


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Macro

Yeah, and since I feel I was snubbing you a bit before (sorry) I'll provide
you with a slightly more elaborate reply this time.

The method is rather talkative and lengthy, but I've tried to be as clear as
possible.

HTH,
/MP

==================================================

Private Sub PivotTableTest()

On Error GoTo ErrorHandler

Dim oSourceSheet As Worksheet
Dim oTargetSheet As Worksheet

' TODO: Change the workbook names (enclosed in "")
' to the appropriate values you should be using.
Set oSourceSheet = Workbooks("MySourceDataSheet")
Set oTargetSheet = Workbooks("MyTargetDataSheet")

Dim oPC As PivotCache
Dim oPT As PivotTable

Set oPC = ActiveWorkbook.PivotCaches.Add( _
SourceType:=xlDatabase, _
SourceData:="'" & oSourceSheet.Name & "'!R21C2:R65536C8")

' TODO: Change the range to point to the upper left
' cell of the destination range you want to use.
Set oPT = oPC.CreatePivotTable( _
TableDestination:=oTargetSheet.Range("A1"), _
TableName:="PivotTable2")

Exit Sub

ErrorHandler:
' Spit out some additional info about any error that may occur
MsgBox "Error (" & CStr(Err.Number) & ") : " & Err.Description

End Sub

================================================== =




"Tom Ogilvy" wrote:

Yes, I believe TableDestination is a required argument. So why not supply
one.

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, _
SourceData:="'" & Activehseet.Name & "'!R21C2:R65536C8") _
.CreatePivotTable TableDestination:=Activesheet.Range("M1"), _
TableName:="PivotTable2"

--
Regards,
Tom Ogilvy



"Nbiggss" wrote:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'" & Activehseet.Name & "'!R21C2:R65536C8").CreatePivotTable
TableDestination:="", _TableName:="PivotTable2"

Error: Argument not optional.

I think this comes from the last section of the above TableDestination:=""

Help


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Macro

....And it'd be even better if my code was working (d'oh!)

Change the buggy lines:

Set oSourceSheet = Workbooks("MySourceDataSheet")
Set oTargetSheet = Workbooks("MyTargetDataSheet")

Into something more applicable:

Set oSourceSheet = Worksheets("MySourceDataSheet")
Set oTargetSheet = Worksheets("MyTargetDataSheet")

And another thing: do you really have data in the entire range
[R21C2:R65536C8] ? Shouldn't the range reflect the amount of data you've got?
In my test code I got an error when I didn't accurately set the data range,
i.e., when I the range included all the rows in the sheet.

Cheers,
/MP

"Mat P:son" wrote:

Yeah, and since I feel I was snubbing you a bit before (sorry) I'll provide
you with a slightly more elaborate reply this time.

The method is rather talkative and lengthy, but I've tried to be as clear as
possible.

HTH,
/MP

==================================================

Private Sub PivotTableTest()

On Error GoTo ErrorHandler

Dim oSourceSheet As Worksheet
Dim oTargetSheet As Worksheet

' TODO: Change the workbook names (enclosed in "")
' to the appropriate values you should be using.
Set oSourceSheet = Workbooks("MySourceDataSheet")
Set oTargetSheet = Workbooks("MyTargetDataSheet")

Dim oPC As PivotCache
Dim oPT As PivotTable

Set oPC = ActiveWorkbook.PivotCaches.Add( _
SourceType:=xlDatabase, _
SourceData:="'" & oSourceSheet.Name & "'!R21C2:R65536C8")

' TODO: Change the range to point to the upper left
' cell of the destination range you want to use.
Set oPT = oPC.CreatePivotTable( _
TableDestination:=oTargetSheet.Range("A1"), _
TableName:="PivotTable2")

Exit Sub

ErrorHandler:
' Spit out some additional info about any error that may occur
MsgBox "Error (" & CStr(Err.Number) & ") : " & Err.Description

End Sub

================================================== =




"Tom Ogilvy" wrote:

Yes, I believe TableDestination is a required argument. So why not supply
one.

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, _
SourceData:="'" & Activehseet.Name & "'!R21C2:R65536C8") _
.CreatePivotTable TableDestination:=Activesheet.Range("M1"), _
TableName:="PivotTable2"

--
Regards,
Tom Ogilvy



"Nbiggss" wrote:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'" & Activehseet.Name & "'!R21C2:R65536C8").CreatePivotTable
TableDestination:="", _TableName:="PivotTable2"

Error: Argument not optional.

I think this comes from the last section of the above TableDestination:=""

Help


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
Macro recorded... tabs & file names changed, macro hangs Steve Excel Worksheet Functions 3 October 30th 09 11:41 AM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
how to count/sum by function/macro to get the number of record to do copy/paste in macro tango Excel Programming 1 October 15th 04 01:16 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 08:55 AM.

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"