Avatar of dlan75
dlan75
Flag for France asked on

Excel macro refreshing multiple DCT

Hi all,
I have an excel spreadsheet containing around 15 excel DCT.
On that sheet, there is a drop down menu allowing selecting a username, and when changing the value, a macro updates all the DTC present on the spreadsheet with the username and refreshes the data.
Problem is that now for any reason, it crashes excel except on high perf computer.
I don't know what to do

Here is the macro :

Dim pt As PivotTable
Dim pi As PIVOTITEM
Dim strField As String

strField = "Cslts"

On Error Resume Next
'Application.EnableEvents = False
'Application.ScreenUpdating = False

    If Target.Address = Range("H1").Address Then
       
       
            For Each pt In ActiveSheet.PivotTables
                With pt.PageFields(strField)
                    For Each pi In .PivotItems
                        If pi.Value = Target.Value Then
                            .CurrentPage = Target.Value
                    Exit For
                       
                        Else
                            .CurrentPage = "(blank)"
                               
                        End If
                    Next pi
                End With
            Next pt
   
    End If

End Sub

Regards,
Microsoft ExcelVBAMicrosoft Office

Avatar of undefined
Last Comment
dlan75

8/22/2022 - Mon
Mike in IT

have you tried stepping through the code in break mode to see where the problem is? Also you should place code in a code block like this:
Dim pt As PivotTable
Dim pi As PIVOTITEM
Dim strField As String

strField = "Cslts"

On Error Resume Next
'Application.EnableEvents = False
'Application.ScreenUpdating = False

    If Target.Address = Range("H1").Address Then
        
        
            For Each pt In ActiveSheet.PivotTables
                With pt.PageFields(strField)
                    For Each pi In .PivotItems
                        If pi.Value = Target.Value Then
                            .CurrentPage = Target.Value
                    Exit For
                        
                        Else
                            .CurrentPage = "(blank)"
                               
                        End If
                    Next pi
                End With
            Next pt
    
    End If

End Sub

Open in new window

ASKER CERTIFIED SOLUTION
dlan75

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
dlan75

ASKER
this solved my problem
Your help has saved me hundreds of hours of internet surfing.
fblack61