Pivot Table Code

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,835
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
Hi All
This is my first post to this site. I used to post on the Office online site but my administrators decided to restrict my access.
My question is:
I would like the code below to refer the Pivot table to the current Active sheet NOT "'[TESTEquipInv_0506.xls]Oct05 WBS'!R6C20" as shown in the code.
Any advice would be appreciated
Regards
Michael M


Option Explicit

Sub PIVOT()
'
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"R1C6:R57C17").CreatePivotTable TableDestination:= _
"'[TESTEquipInv_0506.xls]Oct05 WBS'!R6C20", TableName:="PivotTable2", _
DefaultVersion:=xlPivotTableVersion10
ActiveWorkbook.ShowPivotTableFieldList = True
Application.CommandBars("PivotTable").Visible = False
With ActiveSheet.PivotTables("PivotTable2").PivotFields("WBS Element")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Allocation"), "Sum of Allocation", xlSum
ActiveWorkbook.ShowPivotTableFieldList = False
Range("T6").Select
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Have you tried changing:
"'[TESTEquipInv_0506.xls]Oct05 WBS'!R6C20"
to
activesheet.name & "!R6C20"
or similar?
 
Upvote 0
Pivot table code

Hi Tactps

Thanks for the quick response.
You can probably tell that this was recorded via the recorder and I'm not a VBA expert. I tried a number of options, and yes, I did try your example. Unfortunately, I accidently removed the exclamation mark as well.

I have input your example, with the expected positive result.

Thanks again for your time and input

Regards
Michael
 
Upvote 0

Forum statistics

Threads
1,214,779
Messages
6,121,520
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top