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

Is it possible to trigger a Private sub worksheet change for one range and not another in the same worksheet?
Erik
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Worksheet change subs.

I don't think so. But you could just have your sub exit if the change isn't in
the range you want:

I start a lot of my worksheet_change procedures with lines like this:

If target.cells.count 1 then exit sub
if intersect(target,me.range("a3:b99")) is nothing then exit sub



Erik wrote:

Is it possible to trigger a Private sub worksheet change for one range and not another in the same worksheet?
Erik


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Worksheet change subs.

Hi Erik,

Yes. To demonstrate, the following throws up a msgbox if any cells in the
range A1:C10 are changed and does nothing for any cells outside this range:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng As Range

Set Rng = Me.Range("A1:C10")

If Target.Count 1 Then Exit Sub
If Not Intersect(Target, Rng) Is Nothing Then
'Do something. For example:
MsgBox Target.Address
End If

End Sub

---
Regards,
Norman
"Erik" wrote in message
...
Is it possible to trigger a Private sub worksheet change for one range and

not another in the same worksheet?
Erik



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Worksheet change subs.

Yes.
In the private sub test for the required range and proceed if it is correct.
e.g.
Private Sub SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

If Target.Count 1 Then Exit Sub

If Not Intersect(Target, Range("C5:J5")) Is Nothing then ' C5:J5
represents the range you want.

....your routine

end if


end sub

HTH
Andrew Bourke



"Erik" wrote in message
...
Is it possible to trigger a Private sub worksheet change for one range and

not another in the same worksheet?
Erik



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Worksheet change subs.

Thanks everyone. I had a little infinite loop problem, but your suggestions solved it. I really appreciate all your help.
Erik


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
Combining two Subs Petitboeuf Excel Discussion (Misc queries) 6 April 27th 06 03:42 PM
Stringing Subs Randal W. Hozeski Excel Programming 2 May 28th 04 04:05 PM
calling subs Mike Excel Programming 4 April 8th 04 08:22 PM
Recursive Subs? ExcelMonkey[_74_] Excel Programming 5 February 5th 04 02:54 AM
Passing values between 2 subs ? [email protected] Excel Programming 1 November 21st 03 05:56 PM


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