PC Review


Reply
Thread Tools Rate Thread

Application.Intersect

 
 
notprovided@forobviousreasons.com
Guest
Posts: n/a
 
      21st Jul 2008
Why doesn't this work?

Straight from the microsoft site, or the help files for
Application.Intersect

Worksheets("Sheet1").Activate
Set isect = Application.Intersect(Range("rg1"), Range("rg2"))
If isect Is Nothing Then
MsgBox "Ranges do not intersect"
Else
isect.Select
End If

I opened a new workbook, named two ranges which must intersect per the
procedure, and it displays the messagebox every time. Doesn't matter
if there's a value in the intersected cell or not.
 
Reply With Quote
 
 
 
 
Wigi
Guest
Posts: n/a
 
      21st Jul 2008
Do the 2 named ranges exist in your sheet?

--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music


"(E-Mail Removed)" wrote:

> Why doesn't this work?
>
> Straight from the microsoft site, or the help files for
> Application.Intersect
>
> Worksheets("Sheet1").Activate
> Set isect = Application.Intersect(Range("rg1"), Range("rg2"))
> If isect Is Nothing Then
> MsgBox "Ranges do not intersect"
> Else
> isect.Select
> End If
>
> I opened a new workbook, named two ranges which must intersect per the
> procedure, and it displays the messagebox every time. Doesn't matter
> if there's a value in the intersected cell or not.
>

 
Reply With Quote
 
Lars-Åke Aspelin
Guest
Posts: n/a
 
      21st Jul 2008
On Mon, 21 Jul 2008 15:08:02 -0400, (E-Mail Removed)
wrote:

>Why doesn't this work?
>
>Straight from the microsoft site, or the help files for
>Application.Intersect
>
>Worksheets("Sheet1").Activate
>Set isect = Application.Intersect(Range("rg1"), Range("rg2"))
>If isect Is Nothing Then
> MsgBox "Ranges do not intersect"
>Else
> isect.Select
>End If
>
>I opened a new workbook, named two ranges which must intersect per the
>procedure, and it displays the messagebox every time. Doesn't matter
>if there's a value in the intersected cell or not.



Did you really manage to name the ranges to "rg1" and "rg2"?
I think "rg1" and "rg2" are not valid range name as they conflict with
the cells with the same name.

It you use e.g. "rg_1" and "rg_2" for the range names the result will
be as expected.

Hope this helps. / Lars-Åke
 
Reply With Quote
 
Bernard Liengme
Guest
Posts: n/a
 
      21st Jul 2008
You did not tell us but I suspect you are using Excel 2007
The code works in XL2003 but not in XL2007
Why? because RG1 and RG2 are valid cell references in XL2007
Rename your ranges as myrg1 and myrg2; fix the code to reflect this and all
will be well
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Why doesn't this work?
>
> Straight from the microsoft site, or the help files for
> Application.Intersect
>
> Worksheets("Sheet1").Activate
> Set isect = Application.Intersect(Range("rg1"), Range("rg2"))
> If isect Is Nothing Then
> MsgBox "Ranges do not intersect"
> Else
> isect.Select
> End If
>
> I opened a new workbook, named two ranges which must intersect per the
> procedure, and it displays the messagebox every time. Doesn't matter
> if there's a value in the intersected cell or not.



 
Reply With Quote
 
notprovided@forobviousreasons.com
Guest
Posts: n/a
 
      21st Jul 2008
On Mon, 21 Jul 2008 16:28:12 -0300, "Bernard Liengme"
<(E-Mail Removed)> wrote:

>You did not tell us but I suspect you are using Excel 2007
>The code works in XL2003 but not in XL2007
>Why? because RG1 and RG2 are valid cell references in XL2007
>Rename your ranges as myrg1 and myrg2; fix the code to reflect this and all
>will be well


XL2003

And no, I wasn't able to name the ranges. It appeared I had, which is
why I thought I had, but when I opened the names drop down they
weren't there. I did figure out how to make it work though.

I was looking for the 'apparent' intersection of two cells, assuming
there's an apparent intersection of any two cells, and found it.

It works like this.

Set isect = Application.Intersect(Range("A11").EntireRow,_
Range("D4").EntireColumn)
If isect Is Nothing Then
MsgBox "Ranges do not intersect"
Else
MsgBox isect
End If
End Sub

Thanks for your input. It was my misunderstanding of how it worked.

Note that it didn't work with single named cells without the
..EntireRow and .EntireColumn, but did work with named blocks of cells
which did in fact intersect.

Thanks for the input.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
intersect ranswert Microsoft Excel Programming 12 6th Feb 2008 01:15 PM
Intersect =?Utf-8?B?QXJuZSBIZWdlZm9ycw==?= Microsoft Excel Programming 1 25th Jul 2006 09:38 AM
Intersect Don1975@gmail.com Microsoft Excel Programming 2 19th Jul 2006 10:41 PM
Intersect? =?Utf-8?B?Z2FiYQ==?= Microsoft Excel Programming 0 23rd Nov 2004 06:39 PM
Intersect??? =?Utf-8?B?S2Vpdm4gR3JlZW4=?= Microsoft Excel Worksheet Functions 2 31st Aug 2004 05:59 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:37 PM.