Delete or Disable Macro Assigned to a Specific Sheet When Ran

Ottsel

Board Regular
Joined
Jun 4, 2022
Messages
167
Office Version
  1. 365
Platform
  1. Windows
I have a format macro that is assigned to a sheet that helps with case sensitive material. The problem is once the sheet is done and the formatting is no longer required we process the sheet to be turned into a order, which is done from a macro. The macro is encountering an issue where that sheet macro is causing an issue, but simply delete it from the sheet fixes the issue. My problem is that other people who use this workbook do not understand how to locate the VBA screen and to locate the sheet, so I was hoping to find a way to have a macro that will either delete the code within the active sheet OR disable it within the active sheet.

Any and all help is greatly appreciated.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Sounds like the first code is an 'Event' code (eg WorkSheet_Change) and the second macro is triggering the first code. If that is the case, you could stop that trigger by the second code as follows.

VBA Code:
Sub SecondMacro()
  Application.EnableEvents = False
  'Rest of SecondMacro code goes here
  Application.EnableEvents = False
End Sub
 
Upvote 0
Sounds like the first code is an 'Event' code (eg WorkSheet_Change) and the second macro is triggering the first code. If that is the case, you could stop that trigger by the second code as follows.

VBA Code:
Sub SecondMacro()
  Application.EnableEvents = False
  'Rest of SecondMacro code goes here
  Application.EnableEvents = False
End Sub
Correct. I should of mentioned that to within my question.

This worked nicely, but I must ask: is it required to have
Excel Formula:
  Application.EnableEvents = False

entered at the beginning AND at the end of the code? Was just wondering the reason behind it, as I do know it's good practice to re-enable some features.

Example being
VBA Code:
Application.DisplayAlerts = False 

'input code here

Application.DisplayAlerts = True
then at end of your code to change this back to true to avoid any problems down the road.
 
Upvote 0
I think good practice. Otherwise you (or somebody else) could easily come back to the code at a later time and add more at the end and forget that events were disabled at the beginning.
Disregard the above - see next post
 
Last edited:
Upvote 0
:oops: I didn't read my own post well enough, or yours regarding both EnableEvents lines being False.
Definitely should have the last one as True! I copy/pasted the first one and forgot to edit. :mad:
Sorry if I have misled you.

So ..
VBA Code:
Sub SecondMacro()
  Application.EnableEvents = False
  'Rest of SecondMacro code goes here
  Application.EnableEvents = True
End Sub
 
Last edited:
Upvote 0
Solution
:oops: I didn't read my own post well enough, or yours regarding both EnableEvents lines being False.
Definitely should have the last one as True! I copy/pasted the first one and forgot to edit. :mad:
Sorry if I have misled you.

So ..
VBA Code:
Sub SecondMacro()
  Application.EnableEvents = False
  'Rest of SecondMacro code goes here
  Application.EnableEvents = True
End Sub
No worries. Thank you for clarifying and all your help Peter. I thought it was false, then true, but still pretty new with VBA, so wanted to confirm.
 
Upvote 0

Forum statistics

Threads
1,215,643
Messages
6,125,990
Members
449,278
Latest member
MOMOBI

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top