Share via

Block Selection ‚ALL‘ in PivotFields

Anonymous
2022-09-14T09:25:38.13+00:00

I’ve found this code-snippet in the internet.

'----------------
'----------------
Private Sub Worksheet_PivotTableUpdate _
(ByVal Target As PivotTable)
Dim pf As PivotField
On Error GoTo exit_Handler
Application.EnableEvents = False
Application.ScreenUpdating = False
If ActiveSheet.Name = Me.Name Then
For Each pf In Target.PageFields
If pf.CurrentPage = "(All)" Then
Application.Undo
MsgBox "Please select a single date."
End If
Next pf
End If
exit_Handler:
Set pf = Nothing
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
'----------------
'----------------

This code blocks the ‘ALL’-Selection in all PivotFilterFields.

I want to change it to block the ‘All’-Selcetion only for:
ActiveSheet.PivotTables("PivotTable1").PivotFields("Kost").

I'm a newbie in vba coding with pivottables, so please be gentle.

Thank's a lot in advance

regards
Manfred

Developer technologies | Visual Basic for Applications
0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2022-09-14T11:50:07.237+00:00

    Hello to all,

    i've got the solution by myself.

    ***Private Sub Worksheet_PivottableUpdate _
    (ByVal Target As PivotTable)

    wert = 5 + 1  
    

    Dim pt As PivotTable
    Dim pf As PivotField
    Dim pi As PivotItem
    Set pt = Sheets("pivot").PivotTables(1)
    Set pf = Sheets("pivot").PivotTables(1).PivotFields("Kost")
    If pf = "Kost" Then
    If pf.CurrentPage.Caption = "(Alle)" Then
    Application.Undo
    MsgBox "Selection 'ÄLLE' is not allowed"
    End If
    End If
    Set pf = Sheets("pivot").PivotTables(1).PivotFields("Ort")
    If pf = "Kost" Then
    If pf.CurrentPage.Caption = "(Alle)" Then
    Application.Undo
    MsgBox "Selection 'ÄLLE' is not allowed"
    End If
    End If

    End Sub***

    If you have any improvement, please answer here.

    Thanks a lot to all.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.