Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Worksheet_Change event question

the Worksheet_Change event detects if any cell changes its value, and
assigns this cell to the variable "Target". Thats very good.
My problem is, when I select a range of cells, then press "Delete" to empty
these cells, only the upper left most cell in the range is detected to be
changing its value, and only this cell initiates the Worksheet_Change event.
This is bad because all the cells in the selected range have changed their
values and the event procedure didn't detect them all.
Any Suggestions?
Thanks in advance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Worksheet_Change event question

Well, not exactly...

If you look at Target.Address when a range of cells is selected,
you'll see that Target is the *range* not the top left cell.

That can be a problem, because if, say A1:J10 is selected, and the
activecell is C6, making a change in C6 will return A1:J10 in
Target, with no indication of where the change actually occurred
(and, since we don't know whether the user tabbed or used enter to
complete the change, we can't backtrack from the
..moveafterreturndirection property.

You can build into your function a test for multiple cells being
selected, i.e.,

If Target.Count 1 Then
'multiple cells
Else
'only one cell
End If

Remember that Target need not have contiguous cells - there could be
multiple areas, too.

Play around with this to get the scope of the problem:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
MsgBox "Address: " & Target.Address & vbNewLine & _
"Count: " & Target.Count & vbNewLine & _
"Areas: " & Target.Areas.Count
End Sub





In article ,
"marwan hefnawy" wrote:

the Worksheet_Change event detects if any cell changes its value, and
assigns this cell to the variable "Target". Thats very good.
My problem is, when I select a range of cells, then press "Delete" to empty
these cells, only the upper left most cell in the range is detected to be
changing its value, and only this cell initiates the Worksheet_Change event.
This is bad because all the cells in the selected range have changed their
values and the event procedure didn't detect them all.
Any Suggestions?
Thanks in advance.


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
Worksheet_Change Event with Range Protection Judy P. Excel Discussion (Misc queries) 3 October 28th 10 08:07 PM
Disabling WORKSHEET_CHANGE event Jase Excel Discussion (Misc queries) 1 April 25th 08 04:32 PM
Controling the Worksheet_Change Event? DCSwearingen Excel Discussion (Misc queries) 3 May 25th 06 08:32 PM
xl97 and Worksheet_Change event ? Greg Wilson[_3_] Excel Programming 1 September 10th 03 04:17 AM
Worksheet_Change Event Not Working Michael Beckinsale Excel Programming 0 August 1st 03 02:43 PM


All times are GMT +1. The time now is 02:26 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"