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

I currently use this workaround which works:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 Then Target.Offset(0, 2).Select
If Target.Count 1 Then Exit Sub
If Intersect(Target, Range("E5:E35")) Is Nothing Then Exit Sub
If Target.Value 1 Then
'---continue sub

I would like the input range in Column C to be limited to "C5:E35"
e.g. If Intersect(Target, Range("C5:C35")) Then Target.Offset(0, 2).Select

This gets me to desired cell in Column E, but then things bomb 'Runtime
error 91' as soon as I input anything in "E5:E35"

How to fix?

--
David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 2 conditions in Worksheet_Change event

David,

You're not looking are you? The answer is already in the code, use

If Intersect(Target, Range("C5:C35")) Is Nothing Then Target.Offset(0,
2).Select

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"David" wrote in message
...
I currently use this workaround which works:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 Then Target.Offset(0, 2).Select
If Target.Count 1 Then Exit Sub
If Intersect(Target, Range("E5:E35")) Is Nothing Then Exit Sub
If Target.Value 1 Then
'---continue sub

I would like the input range in Column C to be limited to "C5:E35"
e.g. If Intersect(Target, Range("C5:C35")) Then Target.Offset(0, 2).Select

This gets me to desired cell in Column E, but then things bomb 'Runtime
error 91' as soon as I input anything in "E5:E35"

How to fix?

--
David



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 195
Default 2 conditions in Worksheet_Change event

Bob Phillips wrote

You're not looking are you? The answer is already in the code, use

If Intersect(Target, Range("C5:C35")) Is Nothing Then Target.Offset(0,
2).Select


Well, if it were that obvious, I would have used it. Problem is I only want
that to happen (Target.Offset(0,2).Select) if I enter something in C5:C35.
Your offering moves 2 cols over no matter where I enter something.

--
David
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 195
Default 2 conditions in Worksheet_Change event

David wrote

I currently use this workaround which works:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 Then Target.Offset(0, 2).Select
If Target.Count 1 Then Exit Sub
If Intersect(Target, Range("E5:E35")) Is Nothing Then Exit Sub
If Target.Value 1 Then
'---continue sub

I would like the input range in Column C to be limited to "C5:E35"
e.g. If Intersect(Target, Range("C5:C35")) Then Target.Offset(0,
2).Select

This gets me to desired cell in Column E, but then things bomb
'Runtime error 91' as soon as I input anything in "E5:E35"

How to fix?


This works the way I want:
If Not Intersect(Target, Range("C5:C35")) Is Nothing Then Target.Offset(0,
2).Select

--
David
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 2 conditions in Worksheet_Change event

No you wouldn't because you omitted to test for Is Nothing that is why you
got an error. If you couldn't see that it is unlikely you can solve it.

And it is impossible to be in column C and in E, so better coding would
handle than more efficiently. As it is, rather than re-cut all the code, I
tried to fix it in your style, but I made a small mistake in the code I
posted which I am sure you are now going to spot and solve for yourself.

RP

"David" wrote in message
...
Bob Phillips wrote

You're not looking are you? The answer is already in the code, use

If Intersect(Target, Range("C5:C35")) Is Nothing Then Target.Offset(0,
2).Select


Well, if it were that obvious, I would have used it. Problem is I only

want
that to happen (Target.Offset(0,2).Select) if I enter something in C5:C35.
Your offering moves 2 cols over no matter where I enter something.

--
David



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
Controling the Worksheet_Change Event? DCSwearingen Excel Discussion (Misc queries) 3 May 25th 06 08:32 PM
Setting up Worksheet_Change event Nigel Stevens Excel Programming 2 June 14th 04 02:04 PM
Worksheet_change event Dwayne Smith Excel Programming 2 June 5th 04 03:25 AM
Worksheet_Change Event cmcfalls[_4_] Excel Programming 3 April 12th 04 09:47 PM
Worksheet_Change Event Sam Excel Programming 2 November 21st 03 06:51 PM


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