Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login

POZE MRRRR'S FORUM (VIEW ONLY)

Nu sunteti logat.
Nou pe simpatie:
Alexandrina1 pe Simpatie.ro
Femeie
22 ani
Arges
cauta Barbat
22 - 46 ani
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides / [EXCEL] Prevent Selecting Multiple Options in Slicer Moderat de TRaP, TonyTzu
Autor
Mesaj Pagini: 1
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 748
Source:

Paste the code into the ThisWorkbook Code Module of your Workbook....

Modify "Slicer_MyNames" to match the name of your Slicer.


Private Sub Workbook_SheetPivotTableUpdate(ByVal Sh As Object, _
   ByVal Target As PivotTable)
'--when pivot update event triggered, checks whether a specified slicer
'    has more than one item selected.
'  If so, user is warned and optionally the last action can be undone.

Dim bSlicerIsConnected As Boolean
Dim pvt As PivotTable
Dim slc As SlicerCache
Dim sLastUndoStackItem  As String

'--modify this to match your slicer's name
Const sSLICER_NAME As String =  "Slicer_MyNames"
     
sLastUndoStackItem = Application.CommandBars("Standard").FindControl(ID:=128).List(1)
         
'--validate event was triggered by slicer or filter, not other pivot operation
Select Case sLastUndoStackItem
   Case "Slicer Operation", "Filter"
      'continue
   Case Else
      'do nothing and exit
      GoTo ExitProc
End Select
   
'--validate specified slicer exists
On Error Resume Next
Set slc = SlicerCaches(sSLICER_NAME)
On Error GoTo 0

If slc Is Nothing Then
   GoTo ExitProc
End If

'--validate pvt that triggered event is connected to specified slicer
For Each pvt In slc.PivotTables
   If pvt.Name = Target.Name Then
      bSlicerIsConnected = True
      Exit For
   End If
Next pvt

'--test how many items selected and take action if more than one
If bSlicerIsConnected Then
   If slc.VisibleSlicerItems.Count > 1 Then
      '--option a: only warn user
      'MsgBox "Only one item may be selected" & vbCr _
      '  & "Please undo last selection."
     
      '--option b: warn user and undo
      MsgBox "Only one item may be selected"
      With Application
         .EnableEvents = False
         .Undo
      End With
   End If
End If
ExitProc:
   Application.EnableEvents = True
End Sub


pus acum 4 ani
   
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 748
Other possible solution:

pus acum 4 ani
   
Pagini: 1  

Mergi la