Prevent Macro to run Macro on Worksheet.Change

A

akyhne

I have a sheet with some cells that calls some macros with (Example):

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Name.Name = ("A1") Then

<something>

End Sub

I allso have some Macros that changes the value on ("A1")
When theese Macros want to change cell A1 the worksheet.change should be
ignored or the Code should look something like this:

If Target.Name.Name = ("A1") And Worksheet.Onkey = True Then

<something>

End Sub
 
R

Rog

Prevent your macros from firing the events like this :

Application.EnableEvents = False

'your code to change cell values

'turn on events at end of code

Application.EnableEvents = true

Rgds

Rog
 
A

akyhne

This is only an example. Cell A1 is in a lot of places. As I wrote I have
some Macros that changes A1. In theese Macros I use Application.EnableEvents.
then I have to Write Application.EnableEvents = False just after i changed A1
in my Macros.
No good!!!

"Rog" skrev:
 
R

Rog

I think maybe you're overcomplicating things

All you need to do is to disable the events in your "top
level" macro, and enable them again just before this macro
exits. It then won't care about how many times cell A1 or
any other cell is chaning in the code between the
statements.

This is the easiest way to do it.

Rog
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top