Name

pivottable.DisplayErrorString [= setting]

Synopsis

True displays a custom error when pivot table cells contain errors; False displays the standard error. Default is False.

Set this property to True and ErrorString to "" to turn off error messages, such as #DIV/0!, in the data area of a pivot table. The following code switches error messages on and off for a pivot table on the active worksheet:

Sub ToggleDataFieldErrors(  )
    Dim pt As PivotTable
    ' Run CreateOLAPPivotTable to create this pivot table.
    Set pt = ActiveSheet.PivotTables(1)
    ' Turn error messages on/off.
     pt.DisplayErrorString = Not pt.DisplayErrorString
     pt.ErrorString = ""
End Sub

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.