View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Worksheet_Calculate code in same module as Worksheet Change event goes astray

What do you mean "entered as a separate procedure below the Worksheet_Change
procedure"? You have to incorporate my posted code into your existing
Worksheet_Change procedure's code... where might depend on when you need it
to execute relative to the other code you have. Without seeing the rest of
your code, it is kind of hard to give you any more direction than this.

--
Rick (MVP - Excel)


"Harold Good" wrote in message
...
For some reason this did not work. It works fine on an independent
worksheet with standalone code, but not when entered as a separate
procedure below the Worksheet_Change procedure. It still jumps up into
that other code, and does not bring up the msgbox.

Thanks for any further thoughts you may have.
Harold

Rick Rothstein wrote:
Try your code this way...

If Cells(5, 2) = 1 Then
Application.EnableEvents = False
MsgBox "Fires ok"
Application.EnableEvents = True
End If

Harold Good wrote:
Hi, I'm trying to get some code to fire, based on a formula in cell E2
changing value to equal 1.

Private Sub Worksheet_Calculate()
If Cells(5, 2) = 1 Then MsgBox "Fires ok"
'Application.EnableEvents = False
End Sub

I can get it to work properly on a blank spreadsheet. However I need to
use it on a worksheet that already has a Worksheet Change code. Since it
seems like each worksheet can only have one module (page? not sure of the
right name) for code, the above code is in the same module as the Change
code.

Thus, when the entry is made that changes E2 to equal 1, it starts in the
above code, then jumps to the Change code and begins running some of that
code. If I EnableEvents=False it stops the straying, but still doesn't
bring up the MsgBox.

Any help would be appreciated.
Harold