Intersection - Multiple ranges SUDDENLY not supported

Geronim0

New Member
Joined
Apr 22, 2011
Messages
2
Hello all,

As a starting user of VBA in Excel I have frequently used this forum for solutions to my vba problems (many thanks for that!). This time I couldn't find an answer to my problem, so I decided to register and ask for myself.
I wrote a sub that is fired by the Worksheet_SelectionChange event. I put it in the code page for the Worksheet ("FR") itself. Cut to the bone it looks like this:

Code:
Private Sub Worksheet_SelectionChange (ByVal Target As Range)
 If Not Intersect (Range("C9:R40, C47:R78"), Target) Is Nothing Then
 '(irrelevant code for this problem)
End if
End Sub

This worked perfect, until yesterday. Now I get the error 1004 - method range of object_worksheet has failed (translation of the error is mine, since I have a Dutch Office version).

I changed the code to:

Code:
Private Sub Worksheet_SelectionChange (ByVal Target As Range)
 If Not Intersect ([B]Sheets("FR")[/B].Range("C9:R40, C47:R78"), Target) Is Nothing Then
 '(irrelevant code for this problem)
End if
End Sub

It still results in an error: 1004 - by application or object defined error
Then I found out that the resulting problem is in the fact that I defined multiple ranges.

So when the code is changed to the following, it works:

Code:
Private Sub Worksheet_SelectionChange (ByVal Target As Range)
 If Not Intersect (Sheets("FR").Range([B]"C9:R40"[/B]), Target) Is Nothing Then
 '(irrelevant code for this problem)
End if
End Sub

So it works for a single range but I need to refer to multiple ranges (even more than in the above mentioned example. I already tried to use the names I specified for the ranges in stead of eg C9:R40, but the error remains.

The question is:

- How come I get these 2 errors now and not before yesterday?
- What can I do about it?

Help is much appreciated!

Kind regards,

Geronimo
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Not tested, but I believe you want the ranges as different args in Intersect:
Code:
If Not Application.Intersect(Range("C9:R40"), Range("C47:R78"), Target) Is Nothing Then
 
Upvote 0
Not tested, but I believe you want the ranges as different args in Intersect:
Code:
If Not Application.Intersect(Range("C9:R40"), Range("C47:R78"), Target) Is Nothing Then

I first tried your suggestion, it didn't cause the error but didn't fire the event either. But...

I discovered what went wrong! There were two versions of this excel file open, both with the same worksheet names, range names etc. Closing the other version was the solution.

Thanks for you time and effort, problem solved!
 
Upvote 0

Forum statistics

Threads
1,216,816
Messages
6,132,861
Members
449,761
Latest member
AUSSW

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