PDA

View Full Version : Sleeper: Pivot table naming causing error



Amnicbra
05-31-2005, 12:19 PM
I am trying to add a table to my x number of sheets and the pivot table is names the sheet name but the following code is causeing this error ---

"Run-Time error: '1004'"
"Reference in not valid"

pTableName = "PivotTable-" & vNewSheet

Range("G1").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:="!E5") _
.CreatePivotTable TableDestination:=Range("G1"), TableName:=pTableName

ActiveSheet.PivotTables(pTableName).SmallGrid = False
With ActiveSheet.PivotTables(pTableName).PivotFields("Real Name")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables(pTableName).PivotFields("Real Name")
.Orientation = xlDataField
.Position = 1
End With
Application.CommandBars("PivotTable").Visible = False

Also Having problems passing the variables from module1 to module2 and form (code area):dunno

MWE
05-31-2005, 02:46 PM
what line of code is spawning the error?

Amnicbra
06-01-2005, 06:43 AM
what line of code is spawning the error?


.CreatePivotTable TableDestination:=Range("G1"), TableName:=pTableName

I think its the pTableName Variable
this code is in a seperate module called PivotTable and is being called from a module called main. I have not been able to pass the pTableName from the main module to the PivotTable module but thats a later issue.

Cross Posted here..
http://www.ozgrid.com/forum/showthread.php?p=172789#post172789