Nov 20 2019 01:50 AM
Morning all,
I've had a look in these forums and online but can't see a solution.
I'm after some sort of warning/confirmation notice in excel to appear just before a pivot table is refreshed.
Is this possible? If not, are there any suggestions?
Nov 20 2019 03:38 AM
You may use Worksheet_PivotTableUpdate Event to achieve that.
To do so, follow these steps...
Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim Ans As VbMsgBoxResult
On Error GoTo Skip
Application.ScreenUpdating = False
Application.EnableEvents = False
Ans = MsgBox("Are sure that you want to refresh the Pivot Table?", vbQuestion + vbYesNo, "Confirm Please!")
If Ans = vbNo Then
Application.Undo
MsgBox "Pivot Table is not refreshed.", vbExclamation
Else
MsgBox "Pivot Table has been refreshed successfully.", vbInformation
End If
Skip:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
As per the above event code, when you try to refresh the Pivot Table, it will prompt you to confirm.
If you click on Yes, the Pivot Table will get refreshed successfully but if you click on No, the Pivot Table will not get refreshed.
Let me know if this is what you were trying to achieve.