Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 334
Default Target.Cells.Count

What is the function of
If Target.Cells.Count 1 then
Exit sub
End If

and is it necessary as the first test in a Worksheet_Change(ByValue as
Range) sub?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Target.Cells.Count

This is to make sure that no action is taken if the user changes several
cells at once.
--
Gary''s Student - gsnu200764


"Rick" wrote:

What is the function of
If Target.Cells.Count 1 then
Exit sub
End If

and is it necessary as the first test in a Worksheet_Change(ByValue as
Range) sub?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Target.Cells.Count

It is used to test whether more than one cell is being changed in one go,
and exits if so.

It isn't necessary, it is a choice. You could cater for multiple cells, and
process each one in a loop.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Rick" wrote in message
...
What is the function of
If Target.Cells.Count 1 then
Exit sub
End If

and is it necessary as the first test in a Worksheet_Change(ByValue as
Range) sub?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Target.Cells.Count

On Jan 7, 4:06*pm, Rick wrote:
What is the function of
* If Target.Cells.Count 1 then
* * *Exit sub
* End If

and is it necessary as the first test in a Worksheet_Change(ByValue as
Range) sub? * * * * * * *


Hi
Depends what you are doing. If you want the worksheet_change to
trigger when the value in one cell changes, then you need to check
that more than one cell did not change i.e. other cells you are not
bothered about.
quite often you will see

if intersect(myRange, Target).Count1 then
Exit Sub
End if

so you only want one cell within the range myRange to trigger the
change (note .Cells is not required)

You will also see variants of

Set Testrange = intersect(myRange, Target)
if not Testrange is nothing then
if Testrange.count = 1 then
'do something
else
Exit Sub
end If
End if

So you are checking that Target is within a certain range AND that it
is only one cell, before change is triggered.

Target can be more than one cell though (e.g. a sum of cell values
reaching a value triggers change).

regards
Paul
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
Target cell reference moves when target is cut and pasted Illya Teideman Excel Discussion (Misc queries) 5 May 31st 07 11:34 AM
If target.count 1 Jim May Excel Programming 3 October 19th 06 08:05 PM
count the # of entries when sum matches the target [email protected] Excel Worksheet Functions 4 February 15th 06 01:01 AM
Ranges:Target in Worksheet_SelectionChange(ByVal Target As Range) Kevin McCartney Excel Programming 3 April 15th 05 01:51 PM
Help - loop through cells in a range that are not together (several different cells as Target) Marie J-son[_5_] Excel Programming 4 April 3rd 05 09:54 PM


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

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

About Us

"It's about Microsoft Excel"