vba error - object has disconnected from its client

mwoody1983

New Member
Joined
Apr 15, 2016
Messages
2
Hi,

could someone help please.

I get the following error: automation error the object has disconnected from its clients:


The two pieces of code on their own when the other is commented out work as expected. In another file I have both together work as I need.

However in my current file, same format, they don't work and I get the above error.

Please see the code below:

Code:
[COLOR=#333333]Option Explicit[/COLOR]

[COLOR=#333333]Dim region_range As Range[/COLOR]
[COLOR=#333333]Dim zone_range As Range[/COLOR]
[COLOR=#333333]Dim district_range As Range[/COLOR]


[COLOR=#333333]Set region_range = Range("f9")[/COLOR]
[COLOR=#333333]Set zone_range = Range("f10")[/COLOR]
[COLOR=#333333]Set district_range = Range("f11")[/COLOR]


[COLOR=#333333]If ActiveSheet.AutoFilterMode = False Then[/COLOR]


[COLOR=#333333]Range("a21:c21").AutoFilter[/COLOR]


[COLOR=#333333]End If[/COLOR]


[COLOR=#333333]If Range("f15") = "*Select Question*" Then[/COLOR]
[COLOR=#333333]ActiveSheet.AutoFilterMode = False[/COLOR]


[COLOR=#333333]ElseIf region_range = "All" Then[/COLOR]
[COLOR=#333333]ActiveSheet.AutoFilterMode = False[/COLOR]


[COLOR=#333333]ElseIf region_range <> "All" And zone_range = "All" Then[/COLOR]
[COLOR=#333333]ActiveSheet.AutoFilterMode = False[/COLOR]
[COLOR=#333333]Range("a21:c21").AutoFilter[/COLOR]
[COLOR=#333333]ActiveSheet.Range("$a$21").AutoFilter Field:=1, Criteria1:= _[/COLOR]
[COLOR=#333333]region_range[/COLOR]

[COLOR=#333333]ElseIf region_range <> "All" And zone_range <> "All" And district_range = "All" Then[/COLOR]
[COLOR=#333333]ActiveSheet.Range("$a$21").AutoFilter Field:=1, Criteria1:= _[/COLOR]
[COLOR=#333333]region_range[/COLOR]

[COLOR=#333333]ActiveSheet.Range("$a$21").AutoFilter Field:=2, Criteria1:= _[/COLOR]
[COLOR=#333333]zone_range[/COLOR]

[COLOR=#333333]ActiveSheet.Range("$A$21").AutoFilter Field:=3[/COLOR]


[COLOR=#333333]ElseIf region_range <> "All" And zone_range <> "All" And district_range <> "All" Then[/COLOR]
[COLOR=#333333]ActiveSheet.Range("$a$21").AutoFilter Field:=1, Criteria1:= _[/COLOR]
[COLOR=#333333]region_range[/COLOR]

[COLOR=#333333]ActiveSheet.Range("$a$21").AutoFilter Field:=2, Criteria1:= _[/COLOR]
[COLOR=#333333]zone_range[/COLOR]

[COLOR=#333333]ActiveSheet.Range("$a$21").AutoFilter Field:=3, Criteria1:= _[/COLOR]
[COLOR=#333333]district_range[/COLOR]

[COLOR=#333333]End If[/COLOR]


[COLOR=#333333]End Sub[/COLOR]




[COLOR=#333333]Sub Worksheet_Calculate()[/COLOR]










[COLOR=#333333]Dim KeyCell As Range[/COLOR]




[COLOR=#333333]Set KeyCell = Range("eg1")[/COLOR]


[COLOR=#333333]If ActiveSheet.AutoFilterMode = True Then[/COLOR]


[COLOR=#333333]Range("a21:c21").AutoFilter[/COLOR]


[COLOR=#333333]End If[/COLOR]




[COLOR=#333333]If Not Application.Intersect(KeyCell, Range("eg1")) _[/COLOR]
[COLOR=#333333]Is Nothing Then[/COLOR]
[COLOR=#333333]Range(Range("eg1").Value).Copy[/COLOR]
[COLOR=#333333]Range("a22").Select[/COLOR]
[COLOR=#333333]Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _[/COLOR]
[COLOR=#333333]:=False, Transpose:=False[/COLOR]




[COLOR=#333333]'Range("d21").Select[/COLOR]


[COLOR=#333333]End If[/COLOR]


[COLOR=#333333]End Sub[/COLOR]


Any help will be greatly appreciated, i've been stuck on this problem for two days?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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