ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro unexpectedly jumps to other macros and functions (https://www.excelbanter.com/excel-programming/317772-macro-unexpectedly-jumps-other-macros-functions.html)

Jeff Wright[_2_]

Macro unexpectedly jumps to other macros and functions
 
Greetings!



I've spent hours trying to figure out why the following subroutine
unexpectedly jumps to another subroutine [Sub ToggleButton1_Click()] when it
hits the line "Worksheets("Mirrors").ToggleButton1.Value = False" in the
macro below. What would automatically trigger this macro to jump into
another macro - especially when I have the line "Application.EnableEvents =
False" at the beginning of this macro?



Also, if I rem out the line "Worksheets("Mirrors").ToggleButton1.Value =
False", the macro will instead jump to a user function when it hits the line

Worksheets("Mirrors").Range("D8") = "Clear". (I do have a sheet module
subroutine in this workbook with the line Private Sub Worksheet_Change(ByVal
Target As Range), where range "D8" is the target.)



What am I doing wrong? Your help is much appreciated.



Thanks!



Jeff



Sub MIRROR()

Application.EnableEvents = False

Application.ScreenUpdating = False

ActiveSheet.Unprotect

Worksheets("Mirrors").ToggleButton1.Value = False

Worksheets("Mirrors").Range("D8") = "Clear"

ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True

Range("D8").Select

Application.ScreenUpdating = True

Application.EnableEvents = True

End Sub



Dave Peterson[_5_]

Macro unexpectedly jumps to other macros and functions
 
You didn't like the answer in .excel?

Jeff Wright wrote:

Greetings!

I've spent hours trying to figure out why the following subroutine
unexpectedly jumps to another subroutine [Sub ToggleButton1_Click()] when it
hits the line "Worksheets("Mirrors").ToggleButton1.Value = False" in the
macro below. What would automatically trigger this macro to jump into
another macro - especially when I have the line "Application.EnableEvents =
False" at the beginning of this macro?

Also, if I rem out the line "Worksheets("Mirrors").ToggleButton1.Value =
False", the macro will instead jump to a user function when it hits the line

Worksheets("Mirrors").Range("D8") = "Clear". (I do have a sheet module
subroutine in this workbook with the line Private Sub Worksheet_Change(ByVal
Target As Range), where range "D8" is the target.)

What am I doing wrong? Your help is much appreciated.

Thanks!

Jeff

Sub MIRROR()

Application.EnableEvents = False

Application.ScreenUpdating = False

ActiveSheet.Unprotect

Worksheets("Mirrors").ToggleButton1.Value = False

Worksheets("Mirrors").Range("D8") = "Clear"

ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True

Range("D8").Select

Application.ScreenUpdating = True

Application.EnableEvents = True

End Sub


--

Dave Peterson

Jeff Wright[_2_]

Macro unexpectedly jumps to other macros and functions
 
Dave,

After I posted the question to Excel, I realized that I may have posted to
the wrong newsgroup, which is why I reposted to this newsgroup. It wasn't
until after this posting that I read replies in the Excel group, one of
which was yours, thanks!

5 minutes later . . . . Dave, I tried your solution, and it works! Thanks!
Can you explain to me why it works so I can learn something new? For
instance, I don't understand the three lines you added:

BlkProc = True
Worksheets("Mirrors").ToggleButton1.Value = False
BlkProc = False

And is there a relatively simple answer as to why a line in a macro could
trigger another macro?

Again, thanks for your solution!!

Jeff



"Dave Peterson" wrote in message
...
You didn't like the answer in .excel?

Jeff Wright wrote:

Greetings!

I've spent hours trying to figure out why the following subroutine
unexpectedly jumps to another subroutine [Sub ToggleButton1_Click()] when
it
hits the line "Worksheets("Mirrors").ToggleButton1.Value = False" in the
macro below. What would automatically trigger this macro to jump into
another macro - especially when I have the line "Application.EnableEvents
=
False" at the beginning of this macro?

Also, if I rem out the line "Worksheets("Mirrors").ToggleButton1.Value =
False", the macro will instead jump to a user function when it hits the
line

Worksheets("Mirrors").Range("D8") = "Clear". (I do have a sheet module
subroutine in this workbook with the line Private Sub
Worksheet_Change(ByVal
Target As Range), where range "D8" is the target.)

What am I doing wrong? Your help is much appreciated.

Thanks!

Jeff

Sub MIRROR()

Application.EnableEvents = False

Application.ScreenUpdating = False

ActiveSheet.Unprotect

Worksheets("Mirrors").ToggleButton1.Value = False

Worksheets("Mirrors").Range("D8") = "Clear"

ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True

Range("D8").Select

Application.ScreenUpdating = True

Application.EnableEvents = True

End Sub


--

Dave Peterson




Dave Peterson[_5_]

Macro unexpectedly jumps to other macros and functions
 
Another followup at the other thread.

Jeff Wright wrote:

Dave,

After I posted the question to Excel, I realized that I may have posted to
the wrong newsgroup, which is why I reposted to this newsgroup. It wasn't
until after this posting that I read replies in the Excel group, one of
which was yours, thanks!

5 minutes later . . . . Dave, I tried your solution, and it works! Thanks!
Can you explain to me why it works so I can learn something new? For
instance, I don't understand the three lines you added:

BlkProc = True
Worksheets("Mirrors").ToggleButton1.Value = False
BlkProc = False

And is there a relatively simple answer as to why a line in a macro could
trigger another macro?

Again, thanks for your solution!!

Jeff

"Dave Peterson" wrote in message
...
You didn't like the answer in .excel?

Jeff Wright wrote:

Greetings!

I've spent hours trying to figure out why the following subroutine
unexpectedly jumps to another subroutine [Sub ToggleButton1_Click()] when
it
hits the line "Worksheets("Mirrors").ToggleButton1.Value = False" in the
macro below. What would automatically trigger this macro to jump into
another macro - especially when I have the line "Application.EnableEvents
=
False" at the beginning of this macro?

Also, if I rem out the line "Worksheets("Mirrors").ToggleButton1.Value =
False", the macro will instead jump to a user function when it hits the
line

Worksheets("Mirrors").Range("D8") = "Clear". (I do have a sheet module
subroutine in this workbook with the line Private Sub
Worksheet_Change(ByVal
Target As Range), where range "D8" is the target.)

What am I doing wrong? Your help is much appreciated.

Thanks!

Jeff

Sub MIRROR()

Application.EnableEvents = False

Application.ScreenUpdating = False

ActiveSheet.Unprotect

Worksheets("Mirrors").ToggleButton1.Value = False

Worksheets("Mirrors").Range("D8") = "Clear"

ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True

Range("D8").Select

Application.ScreenUpdating = True

Application.EnableEvents = True

End Sub


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 11:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com