'Intersect of object' - Global failed

Biz

Well-known Member
Joined
May 18, 2009
Messages
1,773
Office Version
  1. 2021
Platform
  1. Windows
Dear All

I am trying to Intersect method but it fails gives run-time error '1004'.
Method 'Intersect of object' - Global failed.

Ranged names are different worksheet Sheets(B) and Activesheet Sheets ("A") . Not sure why it is not working.



Code:
Set tAG = Sheets("B").Range("tAGt")
Set tAT = Sheets("B").Range("tATt")
'AG Changes
    If Not Intersect(Range("E12"), tAG) Is Nothing Then
        Range("E14").Value = ""
        Range("E16").Value = ""
    'AT Changes
    ElseIf Not Intersect(Range("E14"), tAT) Is Nothing Then
        Range("E16").Value = ""
    End If

Your help would be greatly appreciated

Biz
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
If the ranges are on different sheets, they can't intersect, so I'm not sure what you are trying to do.
 
Upvote 0
Hope below statements help.

If someone changes Sheets("A").Range("E12") Then blank out
Sheets("A").Range("E14").Value = ""
Sheets("A"). Range("E16").Value = ""

ElseIf Sheets("A").Range("E14")Then
Range("E16").Value = ""
End If

Biz
 
Upvote 0
What does that have to do with Intersect?
 
Upvote 0
Is this code in a Worksheet_Change event?
 
Upvote 0
Yes it is under Worksheet_Change event.
Still not sure how to make it work.

Biz
 
Upvote 0
Hi Rorya,

I finally code working. Back to basics.

Code:
[COLOR=#1f497d][SIZE=3][FONT=Calibri]Private Sub Worksheet_Change(ByVal Target As Range)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#1f497d]<o:p>[FONT=Calibri][SIZE=3] [/SIZE][/FONT]</o:p>[/COLOR]
[COLOR=#1f497d][SIZE=3][FONT=Calibri]'Changes Parent<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#1f497d][SIZE=3][FONT=Calibri]If Target.Address = "$E$12" Then<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#1f497d][SIZE=3][FONT=Calibri]    ActiveSheet.Range("E14").Value = ""<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#1f497d][SIZE=3][FONT=Calibri]    Range("E16").Value = ""<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#1f497d][SIZE=3][FONT=Calibri]End If<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#1f497d]<o:p>[FONT=Calibri][SIZE=3] [/SIZE][/FONT]</o:p>[/COLOR]
[COLOR=#1f497d][SIZE=3][FONT=Calibri]'Changes Child<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#1f497d][SIZE=3][FONT=Calibri]If Target.Address = "$E$14" Then<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#1f497d][SIZE=3][FONT=Calibri]    Range("E16").Value = ""<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#1f497d][SIZE=3][FONT=Calibri]End If<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#1f497d]<o:p>[FONT=Calibri][SIZE=3] [/SIZE][/FONT]</o:p>[/COLOR]
[COLOR=#1f497d][SIZE=3][FONT=Calibri]Application.EnableEvents = True<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=#1f497d][SIZE=3][FONT=Calibri]End Sub<o:p></o:p>[/FONT][/SIZE][/COLOR]

Biz
 
Upvote 0
I would amend that to:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Application.EnableEvents = False
'Changes Parent
If Not Intersect(Target, Range("E12")) is Nothing Then
    Range("E14").Value = ""
    Range("E16").Value = ""
End If

'Changes Child
If Not Intersect(Target, Range("E14")) Is Nothing Then
    Range("E16").Value = ""
End If

Application.EnableEvents = True
End Sub
 
Upvote 0
Hi Rorya,

Thanks your code works very well.

I am using code below. Would it be faster or any faults in my code?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
 
    Select Case True
    Case Target.Address = "$E$12" 'Changes Parent
        Debug.Print Target.Address
        Range("E14").Value = ""
        Range("E16").Value = ""
    Case Target.Address = "$E$14" 'Changes Child
        Debug.Print Target.Address
        Range("E16").Value = ""
    Case Else
        Application.EnableEvents = True
        Exit Sub
    End Select
 
Application.EnableEvents = True
End Sub

Biz
 
Upvote 0
Your code wouldn't do anything if for example you selected E12:E14 and pressed delete. You should also always have an error handler (even if just an On Error Resume Next) if you disable events in your code.
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,558
Members
452,928
Latest member
101blockchains

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