Hi,
To handle such a scenario where the filtered value is not present, you can use error handling in VBA to check if the value exists in the filter and select the blank value if it doesn't.
'//filter only with MSME
With ActiveSheet.PivotTables("MSMEPivottable").PivotFields("MSMED")
.ClearAllFilters
On Error Resume Next
.CurrentPage = "MSME"
If Err.Number <> 0 Then
.CurrentPage = "(blank)" ' Select the blank value if MSME is not present
End If
On Error GoTo 0
End With
In the code above, On Error Resume Next
is used to ignore any errors that occur when setting the filter to a value that doesn't exist. The Err.Number
property is then checked, and if it's non-zero, indicating an error, the filter is set to the blank value "(blank)".
By using this error handling approach, if "MSME" is not present in the filter, it will be automatically changed to the blank value, allowing you to know that there is no data for "MSME" in the pivot table.
Best Regards.