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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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,214,807
Messages
6,121,679
Members
449,047
Latest member
notmrdurden

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