PC Review


Reply
Thread Tools Rate Thread

Compare address to a range

 
 
dhstein
Guest
Posts: n/a
 
      21st Dec 2009
I have this code in an event macro:

If Target.Address = "$BC$3" Or Target.Address = "$BC$4" Or Target.Address =
"$BC$5" Or Target.Address = "$BC$6" Or Target.Address = "$BC$7" Then


Is there a more compact way to write that statement? Thanks for any help on
this.
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      21st Dec 2009
Hi

Look at this:

Set isect = Intersect(Target, Range("BC3:BC7"))
If Not isect Is Nothing Then

or just:

If Not Intersect(Target, Range("BC3:BC7")) Is Nothing Then

Regards,
Per

"dhstein" <(E-Mail Removed)> skrev i meddelelsen
news:B7E07DAC-C0A3-4CB9-9646-(E-Mail Removed)...
>I have this code in an event macro:
>
> If Target.Address = "$BC$3" Or Target.Address = "$BC$4" Or Target.Address
> =
> "$BC$5" Or Target.Address = "$BC$6" Or Target.Address = "$BC$7" Then
>
>
> Is there a more compact way to write that statement? Thanks for any help
> on
> this.


 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      21st Dec 2009
Private Sub Worksheet_Change(ByVal Target As Range)
'does not execute if not in the range
If Intersect(Target, Range("bc3:bc7")) Is Nothing Then Exit Sub
End Sub
'If Target.Address = "$BC$3" Or Target.Address = "$BC$4" Or Target.Address =
'"$BC$5" Or Target.Address = "$BC$6" Or Target.Address = "$BC$7" Then


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"dhstein" <(E-Mail Removed)> wrote in message
news:B7E07DAC-C0A3-4CB9-9646-(E-Mail Removed)...
>I have this code in an event macro:
>
> If Target.Address = "$BC$3" Or Target.Address = "$BC$4" Or Target.Address
> =
> "$BC$5" Or Target.Address = "$BC$6" Or Target.Address = "$BC$7" Then
>
>
> Is there a more compact way to write that statement? Thanks for any help
> on
> this.


 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      21st Dec 2009

Dim isect As Range

Set isect = Application.Intersect(Target, Range("$BC$3:$BC$7"))

If isect Is Nothing Then
MsgBox "Target NOT in range"
Else
MsgBox "Target IS in range"
End If

You can also test against use multiple ranges. (Note that a space and
underscore at the end of a line is a line break in an otherwise single line
of code.)

Set isect = Application.Intersect _
(Target, Union(Range("$BC$3:$BC$7"), _
Range("$BC$13:$BC$17")))


--
Regards,

OssieMac


"dhstein" wrote:

> I have this code in an event macro:
>
> If Target.Address = "$BC$3" Or Target.Address = "$BC$4" Or Target.Address =
> "$BC$5" Or Target.Address = "$BC$6" Or Target.Address = "$BC$7" Then
>
>
> Is there a more compact way to write that statement? Thanks for any help on
> this.

 
Reply With Quote
 
Ryan H
Guest
Posts: n/a
 
      21st Dec 2009
I think this is about as compact as it gets. I hope this helps! If so, let
me know, click "YES" below.

If Not Application.Intersect(Target, Range("BC3:BC7")) Is Nothing Then
' put your code here
End If
--
Cheers,
Ryan


"dhstein" wrote:

> I have this code in an event macro:
>
> If Target.Address = "$BC$3" Or Target.Address = "$BC$4" Or Target.Address =
> "$BC$5" Or Target.Address = "$BC$6" Or Target.Address = "$BC$7" Then
>
>
> Is there a more compact way to write that statement? Thanks for any help on
> this.

 
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
RE: how to compare a date range another range Jacob Skaria Microsoft Excel Programming 1 22nd Apr 2009 02:31 AM
COUNTIF to compare one range versus another range Phil Microsoft Excel Programming 3 30th May 2007 10:39 PM
Re: Look-up and Compare Table Range Then =?Utf-8?B?SmF5?= Microsoft Excel Worksheet Functions 1 30th Aug 2006 06:21 AM
Compare range with another range in other workbook =?Utf-8?B?QXJqYW4=?= Microsoft Excel Worksheet Functions 2 15th Nov 2005 03:31 PM
Compare a selected Range with a Named range and select cells that do not exist PCLIVE Microsoft Excel Programming 1 18th Oct 2005 07:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:01 AM.