I've seen this error message on other posts but none matched my situation.
I have a few AutoFilter functions done one after the other checking if the target cell is empty and moving on if it is.
The code runs until the 6th iteration wherein I get the error
"the object invoked has disconnected from its clients"
Option Explicit
Private Sub CommandButton49_Click()
'
Dim Wsdnd As Worksheet
Set Wsdnd = Sheets("DO NOT DELETE")
Dim A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, ... (more variables) As Range
Set A3 = Wsdnd.Range("BD3")
Set A4 = Wsdnd.Range("BD4")
Set A5 = Wsdnd.Range("BD5")
Set A6 = Wsdnd.Range("BD6")
Set A7 = Wsdnd.Range("BD7")
Set A8 = Wsdnd.Range("BD8")
... (More variables)
'
Wsdnd.Range("BC3:BE50").Calculate 'Refreshing "Category", "Apply All Data", "Match Lookup Value" Lists on DO NOT DELETE sheet
Application.Calculation = xlManual 'Restarts manual calculations only for workbook speed
'
'Filter #4
If Not IsEmpty(A6.Value) Then
Sheets("Database").Range("B$24:BL$71499").AutoFilter Field:=WorksheetFunction.Match(Sheets("DO NOT DELETE").Range("BE6"), _
Worksheets("Database").Range("B23:BL23"), 0), Criteria1:=A6.Value, Operator:=xlFilterValues
Else
End If
'
'Filter #5
If Not IsEmpty(A7.Value) Then
Sheets("Database").Range("B$24:BL$71499").AutoFilter Field:=WorksheetFunction.Match(Sheets("DO NOT DELETE").Range("BE7"), _
Worksheets("Database").Range("B23:BL23"), 0), Criteria1:=A7.Value, Operator:=xlFilterValues
Else
End If
'
'Filter #6
If Not IsEmpty(A8.Value) Then
Sheets("Database").Range("B$24:BL$71499").AutoFilter Field:=WorksheetFunction.Match(Sheets("DO NOT DELETE").Range("BE8"), _
Worksheets("Database").Range("B23:BL23"), 0), Criteria1:=A8.Value, Operator:=xlFilterValues
Else
End If
'
'... Filters continue
The data being called in the variables is:
String ("F8442")
String ("Unspecified")
Integer ("345")
I wasn't sure if the data type above would be an issue since they were referring to a cell and many times the cell value can change from text to a number and vice versa.
I had left out Range.Calculate and Application.Calculation = xlManual as I didn't think they would have an affect on the code but added them here as I'm not sure. When taken out of the code it gives the error at the same location.