Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Worksheet_Change and Application.undo

I have the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$F$83" And Target.Value = 1 And Target.Value
<= 4 Then
' do something
Else
Application.Undo
End If
End Sub

To start with, lets say F83 has 3. Now my problem is, if I enter say 5 in
F83, then the above code is triggered, and through the Else, Application
Undo is triggered, and 3 is entered again in F83. But this again triggers
the changes event.

My question: Can this second trigger be avoided somehow?

I don't want to use the Data Validation, as the above thing is just a
small part of what I am trying to do.

--
- Mangesh
------------------------------------------
Office XP & Windows XP


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Worksheet_Change and Application.undo

putting

Application.EnableEvents = False

before application.undo seems to be working for me.


Mangesh



"Mangesh Yadav" wrote in message
...
I have the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$F$83" And Target.Value = 1 And Target.Value
<= 4 Then
' do something
Else
Application.Undo
End If
End Sub

To start with, lets say F83 has 3. Now my problem is, if I enter say 5 in
F83, then the above code is triggered, and through the Else, Application
Undo is triggered, and 3 is entered again in F83. But this again triggers
the changes event.

My question: Can this second trigger be avoided somehow?

I don't want to use the Data Validation, as the above thing is just a
small part of what I am trying to do.

--
- Mangesh
------------------------------------------
Office XP & Windows XP




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Worksheet_Change and Application.undo

Mangesh,

A couple of points

make sure you reset
and add error trappin g to rest on error

Like so

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
With Target
If .Address = "$F$83" And .Value = 1 And .Value <= 4 Then
'do your stuff
End If
End With

ws_exit:
Application.EnableEvents = True
End Sub

--
HTH

Bob Phillips

"Mangesh Yadav" wrote in message
...
putting

Application.EnableEvents = False

before application.undo seems to be working for me.


Mangesh



"Mangesh Yadav" wrote in message
...
I have the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$F$83" And Target.Value = 1 And

Target.Value
<= 4 Then
' do something
Else
Application.Undo
End If
End Sub

To start with, lets say F83 has 3. Now my problem is, if I enter say 5

in
F83, then the above code is triggered, and through the Else, Application
Undo is triggered, and 3 is entered again in F83. But this again

triggers
the changes event.

My question: Can this second trigger be avoided somehow?

I don't want to use the Data Validation, as the above thing is just a
small part of what I am trying to do.

--
- Mangesh
------------------------------------------
Office XP & Windows XP






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Worksheet_Change and Application.undo

Hi Bob,

Thanks. Have taken care of both the points. I was presuming that I already
had the EnableEvents 'off', and still it was not working. Anyway, thanks.

Mangesh




"Bob Phillips" wrote in message
...
Mangesh,

A couple of points

make sure you reset
and add error trappin g to rest on error

Like so

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
With Target
If .Address = "$F$83" And .Value = 1 And .Value <= 4 Then
'do your stuff
End If
End With

ws_exit:
Application.EnableEvents = True
End Sub

--
HTH

Bob Phillips

"Mangesh Yadav" wrote in message
...
putting

Application.EnableEvents = False

before application.undo seems to be working for me.


Mangesh



"Mangesh Yadav" wrote in message
...
I have the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$F$83" And Target.Value = 1 And

Target.Value
<= 4 Then
' do something
Else
Application.Undo
End If
End Sub

To start with, lets say F83 has 3. Now my problem is, if I enter say 5

in
F83, then the above code is triggered, and through the Else,

Application
Undo is triggered, and 3 is entered again in F83. But this again

triggers
the changes event.

My question: Can this second trigger be avoided somehow?

I don't want to use the Data Validation, as the above thing is just

a
small part of what I am trying to do.

--
- Mangesh
------------------------------------------
Office XP & Windows XP








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
Why is my undo function in Excel only can undo the last 1 or 2 ch. 1111111111111111111111111111111111111111 Excel Worksheet Functions 1 November 24th 04 11:13 AM
Application.Undo Problem pgjoshi[_5_] Excel Programming 1 May 6th 04 01:42 PM
Worksheet_Change & Undo Mike Excel Programming 4 December 14th 03 03:48 AM
worksheet_change vs. calculate, and worksheet_change not running Tom Ogilvy Excel Programming 1 July 14th 03 02:51 AM
worksheet_change vs. calculate, and worksheet_change not running Ross[_5_] Excel Programming 0 July 13th 03 04:27 PM


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