VBA Getpivottable Data no info

Gregorys05

Board Regular
Joined
Sep 24, 2008
Messages
217
Hi,

i have the below code that keeps erroring when there is not any data for a specific date, how do i get the value to equal 0 if it can not find the data.

Rich (BB code):
Sub LoopRow2()
Workbooks.Open Filename:= _
       "\\Cofunds\Cofunds\data\AWD BI\Support & Control\AWD BI - Amendment Turnaround & Error Type Analysis v14.xls"
Dim Cell As Range
Dim PT As PivotTable
Set PT = Workbooks("AWD BI - Amendment Turnaround & Error Type Analysis v14.xls").Worksheets("DEALAMEND MI Summary").PivotTables("PivotTable4")
For Each Cell In Workbooks("Dashboard MI Daily.xls").ActiveSheet.Range("M3:AF3")
    
    T = Cell.Value
    i = WeekdayName(Weekday(Cell.Value), True, vbSunday)
    If Cell.Value = Date Then Exit Sub
    
    If i = "Mon" Then
 
        Select Case T
            Case Is < Date
            
            Cell.Offset(1, 0).FormulaR1C1 = PT.GetPivotData("Final P/L", "PROCESSED_DATE", Cell.Value) + PT.GetPivotData("Final P/L", "PROCESSED_DATE", (Cell.Value - 1)) + PT.GetPivotData("Final P/L", "PROCESSED_DATE", (Cell.Value - 2))
        
        End Select
             
Else
    Select Case T
            Case Is < Date
            Cell.Offset(1, 0).FormulaR1C1 = PT.GetPivotData("Final P/L", "PROCESSED_DATE", Cell.Value)
        End Select
End If
Next Cell
End Sub

Thanks
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
What im trying to get is
If PT.GetPivotData("Final P/L", "PROCESSED_DATE", Cell.Value-1) errors then
PT.GetPivotData("Final P/L", "PROCESSED_DATE", Cell.Value-1) = 0
 
Upvote 0
Does this work (snippet)?

Code:
On Error Resume Next
Cell.Offset(1, 0).FormulaR1C1 = PT.GetPivotData("Final P/L", "PROCESSED_DATE", Cell.Value) + PT.GetPivotData("Final P/L", "PROCESSED_DATE", (Cell.Value - 1)) + PT.GetPivotData("Final P/L", "PROCESSED_DATE", (Cell.Value - 2))
If Err <> 0 Then
    Err.Clear
    Cell.Offset(1, 0).Value = 0
End If
On Error GoTo 0
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,881
Members
452,948
Latest member
Dupuhini

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