VBA code slicer update

Nas1980

New Member
Joined
Jul 11, 2015
Messages
1
Hi everyone,

I have vba code that connects slicers with different source of data. For some workbooks works but for my workbook it does not work. However, on my case, when I play the code for some reason the code is processing forever. It never stops. In the background it updates and it never stops. When I click escape it takes me to the code and I highlights this line siLong.Selected = False. I would appreciate if someone could look at this and help me to understand why it process the exercise for so long.

Option Explicit
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim wb As Workbook
Dim scMain As SlicerCache
Dim scTemp1 As SlicerCache
Dim scTemp2 As SlicerCache
Dim scTemp3 As SlicerCache

On Error GoTo errHandler
Application.ScreenUpdating = False
Application.EnableEvents = False


Set wb = ThisWorkbook
Set scMain = wb.SlicerCaches("Slicer_Country")
Set scTemp1 = wb.SlicerCaches("Slicer_Country1")
Set scTemp2 = wb.SlicerCaches("Slicer_Country2")
Set scTemp3 = wb.SlicerCaches("Slicer_Country3")


UpdateSlicer scMain, scTemp1
UpdateSlicer scMain, scTemp2
UpdateSlicer scMain, scTemp3


exitHandler:
Application.ScreenUpdating = True
Application.EnableEvents = True
Exit Sub


errHandler:
MsgBox "Could not update pivot table"
Resume exitHandler


End Sub


Sub UpdateSlicer(scShort As SlicerCache, scLong As SlicerCache)
Dim siShort As SlicerItem
Dim siLong As SlicerItem


scLong.ClearManualFilter

For Each siLong In scLong.VisibleSlicerItems
Set siLong = scLong.SlicerItems(siLong.Name)
Set siShort = Nothing
On Error Resume Next
Set siShort = scShort.SlicerItems(siLong.Name)
On Error GoTo errHandler
If Not siShort Is Nothing Then
If siShort.Selected = True Then
siLong.Selected = True
ElseIf siShort.Selected = False Then
siLong.Selected = False
End If
Else
siLong.Selected = False
End If
Next siLong

Exit Sub
errHandler:
MsgBox "Could not update pivot table"


End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,215,085
Messages
6,123,030
Members
449,092
Latest member
ikke

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