Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
....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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro recorded... tabs & file names changed, macro hangs | Excel Worksheet Functions | |||
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort | Excel Worksheet Functions | |||
how to count/sum by function/macro to get the number of record to do copy/paste in macro | Excel Programming | |||
macro to delete entire rows when column A is blank ...a quick macro | Excel Programming | |||
Start Macro / Stop Macro / Restart Macro | Excel Programming |