Consulting

Results 1 to 3 of 3

Thread: Sleeper: Pivot table naming causing error

  1. #1

    Sleeper: Pivot table naming causing error

    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)

  2. #2
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    what line of code is spawning the error?

  3. #3
    Quote Originally Posted by MWE
    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/showthre...789#post172789

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •