VBA to stop Pivot Table refreshing if blank date will ungroup groupings

daithiboy

Board Regular
Joined
Jul 1, 2016
Messages
77
Morning All,

I'm trying to avoid my dozens of pivot tables date groupings being lost in the event of a date being accidentally left blank in the source data.

I've been toying around with the PivotTableBeforeAllocateChanges event but have had no joy, it just doesn't seem to work.

As a test I wrote a macro to replace any blank dates with "0" to prevent the groupings being lost, this works in isolation but doesn't work when I try and use it with the worksheet event above.

I found this on microsoft but can't make it work for me. The only addition I'd like to make is a check of table column "D" to make sure there are no blanks and alert me and allow me to cancel the update if there is, this part is below.

VBA Code:
Sub Worksheet_PivotTableBeforeAllocateChanges(ByVal TargetPivotTable As PivotTable, _  ByVal ValueChangeStart As Long, ByVal ValueChangeEnd As Long, Cancel As Boolean)  
Dim UserChoice As VbMsgBoxResult 
UserChoice = MsgBox("Allow updates to be applied to: " + TargetPivotTable.Name + "?", vbYesNo) 
If UserChoice = vbNo Then 
Cancel = True  
End Sub

Any help would be greatly appreciated.

Ta,
Dave
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi,
You mentioned your problem starts if the date is being accidently left blank.
What about adding validation to make sure the dates are not blank, if they are then do not refresh pivottables?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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