Using a variable within Pivot Table Source Data property

jbunn

New Member
Joined
Feb 6, 2013
Messages
30
May I request assistance on using variables within a Pivot Table Source Data property. I am receiving an error when using the following code
Rich (BB code):
   'Create Pivot Table off of Consolidated Employee Data
         Dim LR As Long
Dim LC As Long
    LR = Range("A:AO").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    LC = Range("A:AO").Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    
    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _
        SourceData:="Consolidated Projects!R1C1:R&"LR"C&"LC"", _
        Version:=xlPivotTableVersion14).CreatePivotTable _
        TableDestination:="", _
        TableName:="PivotTable9", _
        DefaultVersion _
        :=xlPivotTableVersion14
    
    With ActiveSheet.PivotTables("pivottable9").PivotFields("BST Project Code")
        .Orientation = xlRowField
        .Position = 1
    ActiveSheet.PivotTables("PivotTable9").PivotFields ("Source")
        .Orientation = xlColumnField
        .Position = 1
    End With
 
Last edited by a moderator:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Close. :)

Rich (BB code):
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _
SourceData:="'Consolidated Projects'!R1C1:R" & LR & "C" & LC, _
Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="", _
TableName:="PivotTable9", _
DefaultVersion _
:=xlPivotTableVersion14
 
Upvote 0

Forum statistics

Threads
1,214,962
Messages
6,122,482
Members
449,088
Latest member
Melvetica

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