PDA

View Full Version : Pivot table in VB



joesomervill
10-29-2007, 10:04 AM
Version of the program ? Excel 2000
What you want it to do ? trying to create a pivot table, based on a data set that changes in length

Error messages Run-time Error ?438?: Object doesn?t support this property or method
Ok so the above is the quick details of whats happening. I get this error on the highlighted in red below. Please disregard the Loop if you think it might be too slow, I will be fixing that as soon as I resolve this issue. When I debug (I am not the most advanced user of VB), I run the cursor over were it says PTcache and I get PTcache = Nothing. Not sure if that means anything. Any help would be appriciated. Also, when I check the variables for Finalcol and Finalrow, they are correct. Also, I have tried to replace PRange with the actual cells (ie range("A1", "106") or cells(106,1).



Sub Resolution_deleation()


Columns("A:A").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlToRight
Range("A1").Select
ActiveCell.FormulaR1C1 = "Promise 2"
Range("A2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[1]>0,VLOOKUP(RC[1],dates,3),"""")"
Range("A2").Select
Do
If ActiveCell.Offset(rowoffset:=0, columnoffset:=1) = 0 Then
ActiveCell = "(1) No PD"
Else
ActiveCell = "=IF(RC[1]>0,VLOOKUP(RC[1],dates,3),"""")"
End If
ActiveCell.Offset(rowoffset:=1, columnoffset:=0).Activate
If ActiveCell.Offset(rowoffset:=0, columnoffset:=2) = 0 Then Exit Do
Loop
Range("A1:F1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=4, Criteria1:="Resolution"
Range("A2", Range("E65536").End(xlUp)).Select
Selection.EntireRow.Delete
Selection.AutoFilter Field:=4
Selection.AutoFilter Field:=5, Criteria1:="=Consumer Centurion", Operator _
:=xlOr, Criteria2:="=OPEN Centurion"
Range("E2", Range("E65536").End(xlUp)) = "Centurion"
Selection.AutoFilter Field:=5, Criteria1:="<>Centurion", Operator:=xlOr, Criteria2:="=OPEN Centurion"
Range("E2", Range("E65536").End(xlUp)) = "Platinum"
Selection.AutoFilter Field:=5
Range("A2").Select
'FinalRow = Cells(Application.Rows.Count, 1).End(xlUp).Row
'FinalCol = Cells(1, Application.Columns.Count).End(xlToLeft).Column

Dim PTcache As PivotCache
Dim PT As PivotTable
Dim FinalRow As Long
Dim FinalCol As Long
Dim PRange As Range


FinalRow = Worksheets("Pivot1").Cells(Application.Rows.Count, 1).End(xlUp).Row
FinalCol = Worksheets("Pivot1").Cells(1, Application.Columns.Count).End(xlToLeft).Column

Set PRange = Worksheets("Pivot1").Cells(1, 1).Resize(FinalRow, FinalCol)
Set PTcache = Worksheets("Pivot1").PivotCaches.Add(SourceType:=xlDatabase, SourceData:=PRange)
Set PT = PTcache.CreatePivotTable(tableDestination:="", TableName:="PivotTable1")
'PT.AddFields RowFields:=Array("*Owner", "*Topic"), PageFields:="CT"