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

Why does this code not run when the worksheet changes?
It will run correctly if I change the first line to:-
"Private Sub Work()" and then run it manually.
Sandy

Private Sub Worksheet_Change(ByVal Target As Range)

Application.ScreenUpdating = False
Application.EnableEvents = False

For Each mycell In Range("C14:K14,M14:U14")
With mycell
If mycell.Offset(-5).Value = 3 Then
.Value = "Miss"
ElseIf mycell.Offset(-5).Value < 3 Then
mycell.Value = "Hit"
End If
End With
Next mycell

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Worksheet_Change not changing

On Aug 3, 11:59 am, "Sandy" wrote:
Why does this code not run when the worksheet changes?
It will run correctly if I change the first line to:-
"Private Sub Work()" and then run it manually.
Sandy

Private Sub Worksheet_Change(ByVal Target As Range)

Application.ScreenUpdating = False
Application.EnableEvents = False

For Each mycell In Range("C14:K14,M14:U14")
With mycell
If mycell.Offset(-5).Value = 3 Then
.Value = "Miss"
ElseIf mycell.Offset(-5).Value < 3 Then
mycell.Value = "Hit"
End If
End With
Next mycell

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub


Try putting the code in your worksheet rather than thisworkbook...

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 373
Default Worksheet_Change not changing

Sandy,
1. Do you have the subroutine in the worksheet module for the worksheet
that's being changed?
2. Are events turned on?
3. How are you making a change to the worksheet?
James
"Sandy" wrote in message
...
Why does this code not run when the worksheet changes?
It will run correctly if I change the first line to:-
"Private Sub Work()" and then run it manually.
Sandy

Private Sub Worksheet_Change(ByVal Target As Range)

Application.ScreenUpdating = False
Application.EnableEvents = False

For Each mycell In Range("C14:K14,M14:U14")
With mycell
If mycell.Offset(-5).Value = 3 Then
.Value = "Miss"
ElseIf mycell.Offset(-5).Value < 3 Then
mycell.Value = "Hit"
End If
End With
Next mycell

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Worksheet_Change not changing

Does it fire after you close XL and reopen the file?

If an error occurred before events were re-enabled, none of your event
macros will fire. You may want to use this technique instead:

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ErrHandler
Application.ScreenUpdating = False
Application.EnableEvents = False

For Each mycell In Range("C14:K14,M14:U14")
With mycell
If mycell.Offset(-5).Value = 3 Then
.Value = "Miss"
ElseIf mycell.Offset(-5).Value < 3 Then
mycell.Value = "Hit"
End If
End With
Next mycell

ErrHandler:
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

Otherwise, are you sure it's not running (i.e., set a breakpoint at the
first line and initiate a manual change)?

In article ,
"Sandy" wrote:

Why does this code not run when the worksheet changes?
It will run correctly if I change the first line to:-
"Private Sub Work()" and then run it manually.
Sandy

Private Sub Worksheet_Change(ByVal Target As Range)

Application.ScreenUpdating = False
Application.EnableEvents = False

For Each mycell In Range("C14:K14,M14:U14")
With mycell
If mycell.Offset(-5).Value = 3 Then
.Value = "Miss"
ElseIf mycell.Offset(-5).Value < 3 Then
mycell.Value = "Hit"
End If
End With
Next mycell

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Worksheet_Change not changing

James
1. The sub is in "Sheet1(Sheet1)" which is the sheet the data is on.
2. Events turned on ????
3. ("C9:K9,M9:U9") contains integers varying between 2 and 6. I change say a
4 to a 3 or vice versa and nothing occurs.
Sandy

"Zone" wrote in message
...
Sandy,
1. Do you have the subroutine in the worksheet module for the worksheet
that's being changed?
2. Are events turned on?
3. How are you making a change to the worksheet?
James
"Sandy" wrote in message
...
Why does this code not run when the worksheet changes?
It will run correctly if I change the first line to:-
"Private Sub Work()" and then run it manually.
Sandy

Private Sub Worksheet_Change(ByVal Target As Range)

Application.ScreenUpdating = False
Application.EnableEvents = False

For Each mycell In Range("C14:K14,M14:U14")
With mycell
If mycell.Offset(-5).Value = 3 Then
.Value = "Miss"
ElseIf mycell.Offset(-5).Value < 3 Then
mycell.Value = "Hit"
End If
End With
Next mycell

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Worksheet_Change not changing

Closed and reopened file as you suggested and it works fine.
Thanks JE - Why did it require rebooting the application though?
Sandy

"JE McGimpsey" wrote in message
...
Does it fire after you close XL and reopen the file?

If an error occurred before events were re-enabled, none of your event
macros will fire. You may want to use this technique instead:

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ErrHandler
Application.ScreenUpdating = False
Application.EnableEvents = False

For Each mycell In Range("C14:K14,M14:U14")
With mycell
If mycell.Offset(-5).Value = 3 Then
.Value = "Miss"
ElseIf mycell.Offset(-5).Value < 3 Then
mycell.Value = "Hit"
End If
End With
Next mycell

ErrHandler:
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

Otherwise, are you sure it's not running (i.e., set a breakpoint at the
first line and initiate a manual change)?

In article ,
"Sandy" wrote:

Why does this code not run when the worksheet changes?
It will run correctly if I change the first line to:-
"Private Sub Work()" and then run it manually.
Sandy

Private Sub Worksheet_Change(ByVal Target As Range)

Application.ScreenUpdating = False
Application.EnableEvents = False

For Each mycell In Range("C14:K14,M14:U14")
With mycell
If mycell.Offset(-5).Value = 3 Then
.Value = "Miss"
ElseIf mycell.Offset(-5).Value < 3 Then
mycell.Value = "Hit"
End If
End With
Next mycell

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Worksheet_Change not changing

I didn't, but that was the easiest way to get you to test <vbg.

You could have just opened the VBE and hit ctrl-g to get to the immediate window
and typed this:

Application.EnableEvents = True
(and hit enter)

Then gone back to test.

But when you reopen excel, .enableevents are true.

Sandy wrote:

Closed and reopened file as you suggested and it works fine.
Thanks JE - Why did it require rebooting the application though?
Sandy

"JE McGimpsey" wrote in message
...
Does it fire after you close XL and reopen the file?

If an error occurred before events were re-enabled, none of your event
macros will fire. You may want to use this technique instead:

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ErrHandler
Application.ScreenUpdating = False
Application.EnableEvents = False

For Each mycell In Range("C14:K14,M14:U14")
With mycell
If mycell.Offset(-5).Value = 3 Then
.Value = "Miss"
ElseIf mycell.Offset(-5).Value < 3 Then
mycell.Value = "Hit"
End If
End With
Next mycell

ErrHandler:
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

Otherwise, are you sure it's not running (i.e., set a breakpoint at the
first line and initiate a manual change)?

In article ,
"Sandy" wrote:

Why does this code not run when the worksheet changes?
It will run correctly if I change the first line to:-
"Private Sub Work()" and then run it manually.
Sandy

Private Sub Worksheet_Change(ByVal Target As Range)

Application.ScreenUpdating = False
Application.EnableEvents = False

For Each mycell In Range("C14:K14,M14:U14")
With mycell
If mycell.Offset(-5).Value = 3 Then
.Value = "Miss"
ElseIf mycell.Offset(-5).Value < 3 Then
mycell.Value = "Hit"
End If
End With
Next mycell

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub


--

Dave Peterson
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 Jive Excel Worksheet Functions 2 June 11th 07 10:03 AM
Worksheet_Change Job[_2_] Excel Programming 1 August 13th 03 03:23 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 11:24 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"