Warning before pivot table refreshes

Copper Contributor

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?

1 Reply

@Rustle 

You may use Worksheet_PivotTableUpdate Event to achieve that.

To do so, follow these steps...

 

  1. Right Click on Sheet Tab Name which has the Pivot Table and choose View Code.
  2. Copy the code given below and paste it into the opened code window.
  3. Close the VB Editor and save your workbook as Macro-Enabled Workbook.

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.