Hi

I have a macro that works excellent until I copy the code to my Master macro. The code is

---------
Sub Create_PivotTable()
Dim oPC As PivotCache
Dim oPT As PivotTable
Dim oWS As Worksheet
Dim nRows As Integer
Dim nColumns As Integer
Dim rLabel As String
Dim cLabel As String
Dim Content As String
Dim dData As PivotField

'nRows = Application.WorksheetFunction.CountA(dRange)
'nColumns = 3
Worksheets("# Data").Activate
rLabel = ActiveSheet.Cells(1, 1) 'Row labels
cLabel = ActiveSheet.Cells(1, 2) 'Column labels
Content = ActiveSheet.Cells(1, 10) 'Table of content

'oWS.Range(Cells(20, 1), Cells(40, 1)).EntireRow.Delete

Set oWS = ActiveSheet
Set oPC = ActiveWorkbook.PivotCaches.Create(xlDatabase, oWS.UsedRange)
Set oPT = oPC.CreatePivotTable(oWS.[D20], "Table 1", True) '!! Here is my error
Set dData = oPT.PivotFields(Content)
oPT.AddFields rLabel, cLabel
oPT.AddDataField dData, "Table 1", xlSum 'xlCount

End Sub
----------

So when running the Master I get an error message

error msg.jpg

I cant get a grip on why its working in one program but not in my Master. The Master don't have any Pivot tables when the Macro is excecuted. So what is wrong??!!

Please help. Many carma points will be given