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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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,222,902
Messages
6,168,938
Members
452,227
Latest member
sam1121

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