Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Worksheet Change Event macro fails intermittently

My worksheet change event macro is like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False 'prevents change event indefinite loop

<Loop macro resets formulas in 20 rows in one column using counter n

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

The macro works sometimes but fails intermittently. This happens even if I
comment out the EnableEvents = False/True code.
Any ideas on why it could be failing and/or how I could investigate would be
appreciated, thanks.
--
Partho
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Worksheet Change Event macro fails intermittently

When I say the macro (in my original post) fails I mean the macro does not
fire (sometimes) when there is a change done to the worksheet.
--
Partho


"Partho" wrote:

My worksheet change event macro is like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False 'prevents change event indefinite loop

<Loop macro resets formulas in 20 rows in one column using counter n

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

The macro works sometimes but fails intermittently. This happens even if I
comment out the EnableEvents = False/True code.
Any ideas on why it could be failing and/or how I could investigate would be
appreciated, thanks.
--
Partho

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Worksheet Change Event macro fails intermittently

Do you have any "exit sub" lines in the code you didn't share?

How about "End" or "End Sub" in that code?

You may want to post the entire code.

Partho wrote:

My worksheet change event macro is like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False 'prevents change event indefinite loop

<Loop macro resets formulas in 20 rows in one column using counter n

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

The macro works sometimes but fails intermittently. This happens even if I
comment out the EnableEvents = False/True code.
Any ideas on why it could be failing and/or how I could investigate would be
appreciated, thanks.
--
Partho


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Worksheet Change Event macro fails intermittently

The full code is:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False 'prevents change event indefinite loop
'
'Loop through net present value formulas and reset the formulas if any
average age has changed
n = 0
Do Until n = 20 'there are 20 rows
With Range("NPV1").Offset(n, 0)
.FormulaR1C1 = "=NPV(R" & .Row & "C" & .Column - 1 & ",R" & .Row
& "C" & Range("FVYr1").Column & ":R" _
& .Row & "C" & Range("FVYr1").Column +
Range("Yrsto65").Offset(n, 0) - 1 & ")"

End With
'Increment counter by 1 to reset PV formula of next cell down
n = n + 1
'
Loop
'
Application.EnableEvents = True

'Copy paste value in NominalAL1 cell so as to activate change event in
AL worksheet which will reset
'PV formulas in AL sheet
With Sheets("AL Prov").Range("NominalAL1")
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
Application.CutCopyMode = False
Sheets("LSL Prov").Activate
Application.ScreenUpdating = True
End Sub

The bottom part of the code basically does a copy paste value in a cell in
another worksheet so that a change event is triggered in that other worksheet
as well. There is a similar worksheet change event in the other worksheet. I
did this so that the formulas in both the worksheets are in sync.
--
Partho


"Dave Peterson" wrote:

Do you have any "exit sub" lines in the code you didn't share?

How about "End" or "End Sub" in that code?

You may want to post the entire code.

Partho wrote:

My worksheet change event macro is like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False 'prevents change event indefinite loop

<Loop macro resets formulas in 20 rows in one column using counter n

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

The macro works sometimes but fails intermittently. This happens even if I
comment out the EnableEvents = False/True code.
Any ideas on why it could be failing and/or how I could investigate would be
appreciated, thanks.
--
Partho


--

Dave Peterson
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Worksheet Change Event macro fails intermittently

I don't see anything in your code that would turn that .enableevents off.

The next thing I'd look at is this section:

With Sheets("AL Prov").Range("NominalAL1")
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
Application.CutCopyMode = False
Sheets("LSL Prov").Activate
Application.ScreenUpdating = True


Are there any events in the "AL Prov" or "LSL Prov" modules that toggle the
setting and forget to turn it on?

I'd fix that code (if there is). But you could try moving the line:

application.enableevents = true
to the bottom of the routine. Right before the End Sub.

And one more question...

Does the problem occur when you're really using the workbook or when you're
testing? I know that when I'm testing, I'll often (too often!) stop the code
with that .enableevents = false. So I have to type:

application.enableevents = true

into the VBE's immediate window so that I can continue testing.



Partho wrote:

The full code is:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False 'prevents change event indefinite loop
'
'Loop through net present value formulas and reset the formulas if any
average age has changed
n = 0
Do Until n = 20 'there are 20 rows
With Range("NPV1").Offset(n, 0)
.FormulaR1C1 = "=NPV(R" & .Row & "C" & .Column - 1 & ",R" & .Row
& "C" & Range("FVYr1").Column & ":R" _
& .Row & "C" & Range("FVYr1").Column +
Range("Yrsto65").Offset(n, 0) - 1 & ")"

End With
'Increment counter by 1 to reset PV formula of next cell down
n = n + 1
'
Loop
'
Application.EnableEvents = True

'Copy paste value in NominalAL1 cell so as to activate change event in
AL worksheet which will reset
'PV formulas in AL sheet
With Sheets("AL Prov").Range("NominalAL1")
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
Application.CutCopyMode = False
Sheets("LSL Prov").Activate
Application.ScreenUpdating = True
End Sub

The bottom part of the code basically does a copy paste value in a cell in
another worksheet so that a change event is triggered in that other worksheet
as well. There is a similar worksheet change event in the other worksheet. I
did this so that the formulas in both the worksheets are in sync.
--
Partho

"Dave Peterson" wrote:

Do you have any "exit sub" lines in the code you didn't share?

How about "End" or "End Sub" in that code?

You may want to post the entire code.

Partho wrote:

My worksheet change event macro is like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False 'prevents change event indefinite loop

<Loop macro resets formulas in 20 rows in one column using counter n

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

The macro works sometimes but fails intermittently. This happens even if I
comment out the EnableEvents = False/True code.
Any ideas on why it could be failing and/or how I could investigate would be
appreciated, thanks.
--
Partho


--

Dave Peterson
.


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Worksheet Change Event macro fails intermittently

Dave,

Your tip about using the Immediate Window to turn EnableEvents on/off solved
the problem! Thanks.

Partho
--
Partho


"Dave Peterson" wrote:

I don't see anything in your code that would turn that .enableevents off.

The next thing I'd look at is this section:

With Sheets("AL Prov").Range("NominalAL1")
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
Application.CutCopyMode = False
Sheets("LSL Prov").Activate
Application.ScreenUpdating = True


Are there any events in the "AL Prov" or "LSL Prov" modules that toggle the
setting and forget to turn it on?

I'd fix that code (if there is). But you could try moving the line:

application.enableevents = true
to the bottom of the routine. Right before the End Sub.

And one more question...

Does the problem occur when you're really using the workbook or when you're
testing? I know that when I'm testing, I'll often (too often!) stop the code
with that .enableevents = false. So I have to type:

application.enableevents = true

into the VBE's immediate window so that I can continue testing.



Partho wrote:

The full code is:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False 'prevents change event indefinite loop
'
'Loop through net present value formulas and reset the formulas if any
average age has changed
n = 0
Do Until n = 20 'there are 20 rows
With Range("NPV1").Offset(n, 0)
.FormulaR1C1 = "=NPV(R" & .Row & "C" & .Column - 1 & ",R" & .Row
& "C" & Range("FVYr1").Column & ":R" _
& .Row & "C" & Range("FVYr1").Column +
Range("Yrsto65").Offset(n, 0) - 1 & ")"

End With
'Increment counter by 1 to reset PV formula of next cell down
n = n + 1
'
Loop
'
Application.EnableEvents = True

'Copy paste value in NominalAL1 cell so as to activate change event in
AL worksheet which will reset
'PV formulas in AL sheet
With Sheets("AL Prov").Range("NominalAL1")
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
Application.CutCopyMode = False
Sheets("LSL Prov").Activate
Application.ScreenUpdating = True
End Sub

The bottom part of the code basically does a copy paste value in a cell in
another worksheet so that a change event is triggered in that other worksheet
as well. There is a similar worksheet change event in the other worksheet. I
did this so that the formulas in both the worksheets are in sync.
--
Partho

"Dave Peterson" wrote:

Do you have any "exit sub" lines in the code you didn't share?

How about "End" or "End Sub" in that code?

You may want to post the entire code.

Partho wrote:

My worksheet change event macro is like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False 'prevents change event indefinite loop

<Loop macro resets formulas in 20 rows in one column using counter n

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

The macro works sometimes but fails intermittently. This happens even if I
comment out the EnableEvents = False/True code.
Any ideas on why it could be failing and/or how I could investigate would be
appreciated, thanks.
--
Partho

--

Dave Peterson
.


--

Dave Peterson
.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Worksheet Change Event macro fails intermittently

I'm not sure if it solved the problem. It did fix it at least temporarily. But
it doesn't explain why that setting is not getting changed back.

Partho wrote:

Dave,

Your tip about using the Immediate Window to turn EnableEvents on/off solved
the problem! Thanks.

Partho
--
Partho

"Dave Peterson" wrote:

I don't see anything in your code that would turn that .enableevents off.

The next thing I'd look at is this section:

With Sheets("AL Prov").Range("NominalAL1")
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
Application.CutCopyMode = False
Sheets("LSL Prov").Activate
Application.ScreenUpdating = True


Are there any events in the "AL Prov" or "LSL Prov" modules that toggle the
setting and forget to turn it on?

I'd fix that code (if there is). But you could try moving the line:

application.enableevents = true
to the bottom of the routine. Right before the End Sub.

And one more question...

Does the problem occur when you're really using the workbook or when you're
testing? I know that when I'm testing, I'll often (too often!) stop the code
with that .enableevents = false. So I have to type:

application.enableevents = true

into the VBE's immediate window so that I can continue testing.



Partho wrote:

The full code is:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False 'prevents change event indefinite loop
'
'Loop through net present value formulas and reset the formulas if any
average age has changed
n = 0
Do Until n = 20 'there are 20 rows
With Range("NPV1").Offset(n, 0)
.FormulaR1C1 = "=NPV(R" & .Row & "C" & .Column - 1 & ",R" & .Row
& "C" & Range("FVYr1").Column & ":R" _
& .Row & "C" & Range("FVYr1").Column +
Range("Yrsto65").Offset(n, 0) - 1 & ")"

End With
'Increment counter by 1 to reset PV formula of next cell down
n = n + 1
'
Loop
'
Application.EnableEvents = True

'Copy paste value in NominalAL1 cell so as to activate change event in
AL worksheet which will reset
'PV formulas in AL sheet
With Sheets("AL Prov").Range("NominalAL1")
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
Application.CutCopyMode = False
Sheets("LSL Prov").Activate
Application.ScreenUpdating = True
End Sub

The bottom part of the code basically does a copy paste value in a cell in
another worksheet so that a change event is triggered in that other worksheet
as well. There is a similar worksheet change event in the other worksheet. I
did this so that the formulas in both the worksheets are in sync.
--
Partho

"Dave Peterson" wrote:

Do you have any "exit sub" lines in the code you didn't share?

How about "End" or "End Sub" in that code?

You may want to post the entire code.

Partho wrote:

My worksheet change event macro is like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False 'prevents change event indefinite loop

<Loop macro resets formulas in 20 rows in one column using counter n

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

The macro works sometimes but fails intermittently. This happens even if I
comment out the EnableEvents = False/True code.
Any ideas on why it could be failing and/or how I could investigate would be
appreciated, thanks.
--
Partho

--

Dave Peterson
.


--

Dave Peterson
.


--

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 event not running a macro Brettjg Excel Programming 10 April 6th 09 03:42 PM
Worksheet.Unprotect within WorkbookBeforeSave event fails if Save Dean Meyer[_2_] Excel Programming 5 March 30th 09 04:19 PM
Worksheet.Unprotect within WorkbookBeforeSave event fails if Save initiated by VB Dean Meyer Excel Programming 3 June 8th 07 12:30 AM
Cell value change to trigger macro (worksheet change event?) Neil Goldwasser Excel Programming 4 January 10th 06 01:55 PM
Change event fails to work Mark F Excel Worksheet Functions 3 November 10th 05 12:08 PM


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