tezza
Active Member
- Joined
- Sep 10, 2006
- Messages
- 382
- Office Version
- 2016
- 2010
- Platform
- Windows
- Web
Hi, again...
I have a code that runs very well if there are say, 15,000 lines in the worksheet but fails at higher number of rows
The code stops and highlights the code at this part of the code:
A pop up box shows at in the image
The code in that section of the VBA is:
I have a code that runs very well if there are say, 15,000 lines in the worksheet but fails at higher number of rows
The code stops and highlights the code at this part of the code:
VBA Code:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
SrcData, Version:=6).CreatePivotTable TableDestination:= _
"Hours!R1C1", TableName:="Staff_Hours", DefaultVersion:=6
A pop up box shows at in the image
The code in that section of the VBA is:
VBA Code:
Sheets("Sheet1").Select
'ScrData =
SrcData = ActiveSheet.Name & "!" & Range("A1", Range("A1").SpecialCells(xlLastCell)).Address(ReferenceStyle:=xlR1C1)
Sheets.Add(After:=ActiveSheet).Name = "Hours"
Sheets("Hours").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
SrcData, Version:=6).CreatePivotTable TableDestination:= _
"Hours!R1C1", TableName:="Staff_Hours", DefaultVersion:=6
Set pvt = ActiveSheet.PivotTables("Staff_Hours")
'Add item to filter
pvt.PivotFields("Staff Staff Pay Group").Orientation = xlPageField
pvt.PivotFields("Chargeable Rate Sheet").Orientation = xlPageField
'Add item to the Row Labels
pvt.PivotFields("Staff First Name Staff Last Name").Orientation = xlRowField
'Add items to Values
pfName = "Hours"
pvt.AddDataField pvt.PivotFields("Rounded"), pfName, xlSum
pfName = "BasicP"
pvt.AddDataField pvt.PivotFields("Basic"), pfName, xlSum
pfName = "DomP"
pvt.AddDataField pvt.PivotFields("Dom_care"), pfName, xlSum
pfName = "Spt"
pvt.AddDataField pvt.PivotFields("Specialist Task"), pfName, xlSum
pfName = "WeekendP"
pvt.AddDataField pvt.PivotFields("Weekend"), pfName, xlSum
pfName = "OfficeP"
pvt.AddDataField pvt.PivotFields("Office"), pfName, xlSum
pfName = "On-Call"
pvt.AddDataField pvt.PivotFields("DC/On-Call"), pfName, xlSum
pfName = "TT"
pvt.AddDataField pvt.PivotFields("Travel Time"), pfName, xlSum
pvt.CalculatedFields.Add Name:="All Staff Mileage", Formula:="=Staff Mileage + Community Mileage"
pfName = "All_staff_mileage"
pvt.AddDataField pvt.PivotFields("All Staff Mileage"), pfName, xlSum
Sheets.Add(After:=ActiveSheet).Name = "Mileage"
Sheets("Mileage").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
SrcData, Version:=6).CreatePivotTable TableDestination:= _
"Mileage!R1C1", TableName:="Client_Mileage", DefaultVersion:=6
Set pvt = ActiveSheet.PivotTables("Client_Mileage")
pvt.PivotFields("Chargeable Rate Sheet").Orientation = xlPageField
'Add item to the Row Labels
pvt.PivotFields("Client First Name Client Last Name").Orientation = xlRowField
'Add items to Values
pfName = "Miles"
pvt.AddDataField pvt.PivotFields("Mileage"), pfName, xlSum
pfName = "Comm_Miles"
pvt.AddDataField pvt.PivotFields("Community Mileage"), pfName, xlSum
End Sub