Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Worksheet Change Events

I am monitoring a column on a worksheet for changes - using the change
event. I check that the column is the correct one and use the value of the
cell to decide on the action to take. Code as follows

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 9 And Target.Value 0 Then
' take some action
End If
End Sub

All works well until I select a Range of cells, then the Target.Value throws
an error.

My questions are

1. How can I test if the user has chosen more than one cell ?

2. How can I iterate through a multi-cell selection and act on each value in
turn?

Many thanks

--
Cheers
Nigel




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Worksheet Change Events

Hi Nigel,

Try something like:

'=============
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng As Range
Dim rCell As Range

Set Rng = Me.Columns("B") '<<==== CHANGE
Set Rng = Intersect(Target, Rng)

If Not Rng Is Nothing Then

For Each rCell In Rng.Cells
'do something, e.g:
MsgBox rCell.Address(0, 0)
Next rCell
End If

End Sub
'<<=============


---
Regards,
Norman


"Nigel" wrote in message
...
I am monitoring a column on a worksheet for changes - using the change
event. I check that the column is the correct one and use the value of the
cell to decide on the action to take. Code as follows

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 9 And Target.Value 0 Then
' take some action
End If
End Sub

All works well until I select a Range of cells, then the Target.Value
throws an error.

My questions are

1. How can I test if the user has chosen more than one cell ?

2. How can I iterate through a multi-cell selection and act on each value
in turn?

Many thanks

--
Cheers
Nigel






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Worksheet Change Events

Many thanks, works fine now

--
Cheers
Nigel



"Norman Jones" wrote in message
...
Hi Nigel,

Try something like:

'=============
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng As Range
Dim rCell As Range

Set Rng = Me.Columns("B") '<<==== CHANGE
Set Rng = Intersect(Target, Rng)

If Not Rng Is Nothing Then

For Each rCell In Rng.Cells
'do something, e.g:
MsgBox rCell.Address(0, 0)
Next rCell
End If

End Sub
'<<=============


---
Regards,
Norman


"Nigel" wrote in message
...
I am monitoring a column on a worksheet for changes - using the change
event. I check that the column is the correct one and use the value of
the cell to decide on the action to take. Code as follows

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 9 And Target.Value 0 Then
' take some action
End If
End Sub

All works well until I select a Range of cells, then the Target.Value
throws an error.

My questions are

1. How can I test if the user has chosen more than one cell ?

2. How can I iterate through a multi-cell selection and act on each value
in turn?

Many thanks

--
Cheers
Nigel








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
Combine 2 worksheet change events nobbyknownowt Excel Discussion (Misc queries) 0 May 28th 10 10:49 AM
Handling Worksheet Events of a Worksheet Created During Runtime. chatterbox Excel Programming 1 April 25th 07 04:50 PM
Worksheet Change Events Philip J Smith Excel Programming 4 March 30th 07 12:28 PM
Understanding change events xhat Excel Programming 6 July 28th 06 02:44 PM
worksheet change event error events disabled Peter[_21_] Excel Programming 2 July 10th 04 08:45 AM


All times are GMT +1. The time now is 07:42 AM.

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"