Link to home
Start Free TrialLog in
Avatar of dlan75
dlan75Flag 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,
Avatar of Mike in IT
Mike in IT
Flag of United States of America image

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
Avatar of dlan75
dlan75
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dlan75

ASKER

this solved my problem