The object invoked has disconnected from its clients

rfletcher35

Active Member
Joined
Jul 20, 2011
Messages
300
Office Version
  1. 365
Platform
  1. Windows
Here is my code and has been working fine at the point it is now failing (in Bold). For some reason I am now getting the error message "The object invoked has disconnected from its clients" can someone please tell me why this is happening.

Once this has occurred it also crashes my workbook to which none of my VBA works and I have to use task manager to close and then re open it!

Help please!!!!
Rich (BB code):
Sub Results()
'
' Results Macro
'
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.DisplayAlerts = False
    Sheets("SAP Abence").Visible = True
    Sheets("MPR Data").Visible = True
    Sheets("Sheet3").Visible = True
    
    Dim rng365 As Range
    Dim CurMonth As Range
    
    Sheets("Results Sheet").Select
    Range("P5:BL3000").Select
    Selection.ClearContents
    
'   365 - 1 Year of Work No Absence
    Set CurMonth = Range("C2")
    With Sheets("MPR Data")
    .Range("$T$4:$AD$4000").AutoFilter Field:=6, Criteria1:=CurMonth.Value, Operator:=xlFilterValues
    .Range("$T$4:$AD$4000").AutoFilter Field:=1, Criteria1:="None", Operator:=xlFilterValues
    On Error GoTo Enditall
    Set rng365 = .Range("T5:AD4000").SpecialCells(xlCellTypeVisible)
    End With
If Not rng365 Is Nothing Then
    rng365.Copy
    Sheets("Results Sheet").Range("P5").PasteSpecial Paste:=xlPasteValues
Enditall:
    
End If
    Application.CutCopyMode = False
    
    With Sheets("MPR Data")
    .Range("$T$4:$AB$3150").AutoFilter Field:=6
    .Range("$T$4:$AB$3150").AutoFilter Field:=1
    .Range("$T$4:$AD$4000").AutoFilter Field:=6, Criteria1:=CurMonth.Value, Operator:=xlFilterValues
    .Range("$T$4:$AD$4000").AutoFilter Field:=1, Criteria1:=">=365", Operator:=xlFilterValues
    On Error GoTo Enditall1
    Set rng365 = .Range("T5:AD4000").SpecialCells(xlCellTypeVisible)
    End With
If Not rng365 Is Nothing Then
    rng365.Copy
    Sheets("Results Sheet").Range("P" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
Enditall1:
End If
    
'   1 Month to Go
   ' Dim OneMonth As Range
    Sheets("MPR Data").Select
    Set CurMonth = Range("I2")
    With Sheets("MPR Data")
    .Range("$T$4:$AB$3150").AutoFilter Field:=6
    .Range("$T$4:$AB$3150").AutoFilter Field:=1
    .Range("$T$4:$AD$4000").AutoFilter Field:=6, Criteria1:=CurMonth.Value, Operator:=xlFilterValues
    .Range("$T$4:$AD$4000").AutoFilter Field:=1, Criteria1:="None", Operator:=xlFilterValues
    On Error GoTo Enditall2
    Set rng365 = .Range("T5:AD4000").SpecialCells(xlCellTypeVisible)
End With
If Not rng365 Is Nothing Then
    rng365.Copy
    Sheets("Results Sheet").Range("AB5").PasteSpecial Paste:=xlPasteValues
    
Enditall2:
End If
    
    With Sheets("MPR Data")
    .Range("$T$4:$AB$3150").AutoFilter Field:=6
    .Range("$T$4:$AB$3150").AutoFilter Field:=1
    .Range("$T$4:$AD$4000").AutoFilter Field:=6, Criteria1:=CurMonth.Value, Operator:=xlFilterValues
    .Range("$T$4:$AD$4000").AutoFilter Field:=1, Criteria1:=">=365", Operator:=xlFilterValues
    On Error GoTo Enditall3
    Set rng365 = .Range("T5:AD4000").SpecialCells(xlCellTypeVisible)
    
End With
    If Not rng365 Is Nothing Then
    rng365.Copy
    Sheets("Results Sheet").Range("AB" & Rows.Count).End(xlUp).Offset(1).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Enditall3:
        
End If
    Sheets("MPR Data").Select
    ActiveSheet.Range("$T$4:$AB$3150").AutoFilter Field:=6
    ActiveSheet.Range("$T$4:$AB$3150").AutoFilter Field:=1
    Sheets("Results Sheet").Select
    
    Range("A1").Select
    
    Sheets("SAP Abence").Visible = False
    Sheets("MPR Data").Visible = False
    Sheets("Sheet3").Visible = False
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    Application.DisplayAlerts = True
            
End Sub
 
Last edited by a moderator:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
On a sharing site like OneDrive or Dropbox.
 
Upvote 0

Forum statistics

Threads
1,215,417
Messages
6,124,777
Members
449,187
Latest member
hermansoa

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