Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Testing for a Cell within a range

I an using a "Worksheet_Change" event. I want to test is "Target" is within
a range of Cells.

My range is K7:P7.

I tried: If (Target.Address(False, False) = Range("K7").Address(False,
False) _
And Target.Address(False, False) <= Range("P7").Address(False, False))

When I click on a Cell within, K7 and P7, it get a true response. Good.

But when I click on "M8", I also get a true response, Not good.

What am I doing wrong?

Thank you...


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Testing for a Cell within a range

IF Not Intersect(Target, Range("K7:P7") ) Is Nothing Then
'target is inside the range
End If

"Bruce A. Julseth" wrote in message
...
I an using a "Worksheet_Change" event. I want to test is "Target" is
within a range of Cells.

My range is K7:P7.

I tried: If (Target.Address(False, False) = Range("K7").Address(False,
False) _
And Target.Address(False, False) <= Range("P7").Address(False,
False))

When I click on a Cell within, K7 and P7, it get a true response. Good.

But when I click on "M8", I also get a true response, Not good.

What am I doing wrong?

Thank you...

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Testing for a Cell within a range

Try the following (untestedP

Dim anyR as range
on error resume next
set anyr = intersect(target, range("K7:P7"))
on error goto 0
if anyr is nothing then
'not in range
else
'in range
end if

Its easier to do an Intersect and see if a cell is in a range than other
approaches.

Robert Flanagan
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel


"Bruce A. Julseth" wrote in message
...
I an using a "Worksheet_Change" event. I want to test is "Target" is within
a range of Cells.

My range is K7:P7.

I tried: If (Target.Address(False, False) = Range("K7").Address(False,
False) _
And Target.Address(False, False) <= Range("P7").Address(False,
False))

When I click on a Cell within, K7 and P7, it get a true response. Good.

But when I click on "M8", I also get a true response, Not good.

What am I doing wrong?

Thank you...



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Testing for a Cell within a range

Works like a "Champ"

Thanks...

"Patrick Molloy" wrote in message
...
IF Not Intersect(Target, Range("K7:P7") ) Is Nothing Then
'target is inside the range
End If

"Bruce A. Julseth" wrote in message
...
I an using a "Worksheet_Change" event. I want to test is "Target" is
within a range of Cells.

My range is K7:P7.

I tried: If (Target.Address(False, False) = Range("K7").Address(False,
False) _
And Target.Address(False, False) <= Range("P7").Address(False,
False))

When I click on a Cell within, K7 and P7, it get a true response. Good.

But when I click on "M8", I also get a true response, Not good.

What am I doing wrong?

Thank you...



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Testing for a Cell within a range

Hi,

Try one of these

For a contiguous range
If Not Intersect(Target, Range("A1:A10")) Is Nothing Then

or a none contiguous range
If Not Intersect(Target, Range("A1,C1,E1")) Is Nothing Then

Mike

"Bruce A. Julseth" wrote:

I an using a "Worksheet_Change" event. I want to test is "Target" is within
a range of Cells.

My range is K7:P7.

I tried: If (Target.Address(False, False) = Range("K7").Address(False,
False) _
And Target.Address(False, False) <= Range("P7").Address(False, False))

When I click on a Cell within, K7 and P7, it get a true response. Good.

But when I click on "M8", I also get a true response, Not good.

What am I doing wrong?

Thank you...


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
testing range of cells for part of cell content Daniel Excel Worksheet Functions 5 March 25th 10 08:14 PM
IF Function testing a range and a cell Scott Excel Programming 3 June 27th 07 04:44 PM
Testing Range Extent Nigel RS[_2_] Excel Programming 2 May 17th 07 10:15 AM
Testing if a cell is within a range Conan Kelly Excel Programming 4 September 11th 06 07:41 PM
Cell in Range Testing Function Jim C.[_2_] Excel Programming 2 July 23rd 03 06:59 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"