Excel VBA multiple worksheets with pivot tables need to copy data to new workbook.

Tommy1370

New Member
Joined
Jul 23, 2013
Messages
13
The following Sub asks the user to select a generic template to open, then asks the user to select a source file (to populate the template). The source file is contains a number of worksheets and pivot tables. The sub then selects data from a pivot table and copies it into the template.
I need the source file to be a variable vs. a hard coded pivot table source bc this title changes based on the users selection.

Problem: when the data is copied it only shows REF! instead of the actual data (even when the data is present).

Code:
'Open Generic Report to populate with data
Dim GenericFolderLocation As String
MsgBox "Please select the generic porfolio template..."
GenericFolderLocation = "C:\Users\user.name\Desktop"
   ChDrive GenericFolderLocation
   
  SelectedFile = Application.GetOpenFilename( _
        fileFilter:="Excel Files (*.xls*), *.xls*", MultiSelect:=False)
        
        Workbooks.Open (SelectedFile)
        Set test = ActiveWorkbook
        
Dim SourceFolderLocation As String
Dim FileName As String
Dim SourceFile As String
MsgBox "Please select the data source file..."
SourceFolderLocation = "C\Users\user.name\Desktop"
ChDrive SourceFolderLocation
SourceFile = Application.GetOpenFilename( _
    fileFilter:="Excel Files (*.xls*), *.xls*", MultiSelect:=False)
    
    Workbooks.Open (SourceFile)
    Set wkbk = ActiveWorkbook
    
    test.Activate
    
    'Test1
    'Select empty cell in Chart template 
    Range("C28").Select
    'Populate with pivot table data from sourceFile
    ActiveCell.FormulaR1C1 = _
        "=GETPIVOTDATA(""  Value"",'[wkbk]ActCost_PIVOT'!R3C1,""Team"",""Field1"",""Row Descrption"",""Row1"",""Type"",""DataPoint1"")"
    
    Repeat for next cell
    Range("C27").Select
    ActiveCell.FormulaR1C1 = _
        "=GETPIVOTDATA(""  Value"",'[wkbk]CRActCost_PIVOT'!R3C1,""Team"",""Field1"",""Row Descrption"",""Row1"",""Type"",""DataPoint2"")"
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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