Macro crashes since update of excel to v.2408.

Saab95

New Member
Joined
Mar 26, 2021
Messages
46
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I seek your help again.

I have this VBA:
Sheets("Data_analysis").Select
Set pvFld = ActiveSheet.PivotTables("Data_analysis").PivotFields("Entered on")
strFilter = ActiveWorkbook.Sheets("MAIN").Range("C3").Value
pvFld.PivotFilters.Add2 xlCaptionEquals, , strFilter

It worked perfectly fine until today (excel v.2402 Build 17328.20612).

Now we upgraded to v.2408 (Build 17928.20216) and it crashes with "Run time error 1004 - application-defined or object-defined error"

Any idea why?

Thank you
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
pvFld.PivotFilters.Add2 xlCaptionEquals, , strFilter
Remove number 2 and try like this:

VBA Code:
pvFld.PivotFilters.Add xlCaptionEquals, , strFilter

Or try this approach:
VBA Code:
Sub ver2()
  Dim pvFld As PivotField
  Dim strFilter As Variant
  Dim pItem As PivotItem
  Dim n As Long
  
  Sheets("Data_analysis").Select
  Set pvFld = ActiveSheet.PivotTables("Data_analysis").PivotFields("Entered on")
  strFilter = ActiveWorkbook.Sheets("MAIN").Range("C3").Value
  With ActiveSheet.PivotTables("Data_analysis").PivotFields("Entered on")
    .ClearAllFilters
    For Each pItem In .PivotItems
      If pItem <> strFilter Then
        n = n + 1
        If n < .PivotItems.Count Then
          pItem.Visible = False
        Else
          .ClearAllFilters
          MsgBox "The string does not exist"
        End If
      End If
    Next
  End With
End Sub

🤗
 
Upvote 0
Remove number 2 and try like this:

VBA Code:
pvFld.PivotFilters.Add xlCaptionEquals, , strFilter

Or try this approach:
VBA Code:
Sub ver2()
  Dim pvFld As PivotField
  Dim strFilter As Variant
  Dim pItem As PivotItem
  Dim n As Long
 
  Sheets("Data_analysis").Select
  Set pvFld = ActiveSheet.PivotTables("Data_analysis").PivotFields("Entered on")
  strFilter = ActiveWorkbook.Sheets("MAIN").Range("C3").Value
  With ActiveSheet.PivotTables("Data_analysis").PivotFields("Entered on")
    .ClearAllFilters
    For Each pItem In .PivotItems
      If pItem <> strFilter Then
        n = n + 1
        If n < .PivotItems.Count Then
          pItem.Visible = False
        Else
          .ClearAllFilters
          MsgBox "The string does not exist"
        End If
      End If
    Next
  End With
End Sub

🤗
Thank you for your reply.

Unfortunately, none of them work.

'Add' instead of 'Add2' gives the same error.

And for second option I get an error "Unable to set the visible property of the PivotItem class.
 
Upvote 0

Forum statistics

Threads
1,224,884
Messages
6,181,555
Members
453,053
Latest member
Kiranm13

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