My macro runs fine if I use the F8 key and just step through all of it. When I run the macro I run into two problems:
1. The first problem occurs when I create a pivot table. When the code gets to the Set PT line below, I get an error that starts with "The PivotTable field name is not valid." I have changed all the field names to be letters only. All of the columns have label, the code is selecting the correct range, the first column does not have any blanks, I have tried using different ways of referencing the destination location and different ways of referencing the Table Name (including "PivotTable1") and regardless of what I do, I get the error. However, if I just use the F8 key to step through the lines below, the pivot table is created exactly where and how I want it to be.
Set PRangeOBC = WSD.Cells(1, 1).Resize(FinalRow, 8)
Set PTCache = ActiveWorkbook.PivotCaches.Add (SourceType:=xlDatabase, SourceData:=PRangeOBC.Address)
Set PT = PTCache.CreatePivotTable(TableDestination:="'[Reports Macro Master.xls]RepWeek'!R3C1", TableName _
:="WeeklyPT", DefaultVersion:=xlPivotTableVersion10)
2. Once the table is created I loop through a number of page fields, using filters to get data and then paste it into another workbook. Again, if I just keep hitting the F8 through my loop, everything works and the correct data is copied and pasted where I want it to be. However, if I just press F5 to continue through the loop to create all the reports, I end up with data in the wrong places, or data that isn't copied over at all, but no errors are reported.
Does anyone have any suggestions of what to try to correct these two problems.
Thank you for your help!
1. The first problem occurs when I create a pivot table. When the code gets to the Set PT line below, I get an error that starts with "The PivotTable field name is not valid." I have changed all the field names to be letters only. All of the columns have label, the code is selecting the correct range, the first column does not have any blanks, I have tried using different ways of referencing the destination location and different ways of referencing the Table Name (including "PivotTable1") and regardless of what I do, I get the error. However, if I just use the F8 key to step through the lines below, the pivot table is created exactly where and how I want it to be.
Set PRangeOBC = WSD.Cells(1, 1).Resize(FinalRow, 8)
Set PTCache = ActiveWorkbook.PivotCaches.Add (SourceType:=xlDatabase, SourceData:=PRangeOBC.Address)
Set PT = PTCache.CreatePivotTable(TableDestination:="'[Reports Macro Master.xls]RepWeek'!R3C1", TableName _
:="WeeklyPT", DefaultVersion:=xlPivotTableVersion10)
2. Once the table is created I loop through a number of page fields, using filters to get data and then paste it into another workbook. Again, if I just keep hitting the F8 through my loop, everything works and the correct data is copied and pasted where I want it to be. However, if I just press F5 to continue through the loop to create all the reports, I end up with data in the wrong places, or data that isn't copied over at all, but no errors are reported.
Does anyone have any suggestions of what to try to correct these two problems.
Thank you for your help!