Run Macro

elviajero

Board Regular
Joined
Jun 5, 2015
Messages
97
If cell Sheet 1 A1 = "" then do nothing.
If cell Sheet 1 A1 = "Stop" then run a Macro called "Disable".

Please can someone give me the code I need to put in Sheet 1 to make this work.

Thanks
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
it might be easier just to actually run the macro called Disable.
but
in VBE, in the project list, dbl-click THISWORKBOOK
in the left combo box above the code, select workbook
in the right combo box above the code, select SHEETCHANGE

If Sh.Range("A1").Value = "stop" Then Disable

(note: DISABLE macro MUST be in the same module with the worksheet code above)
 
Last edited:
Upvote 0
Try this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

  Application.EnableEvents = False


    If Intersect(Target, Range("$A$1")) = "Stop" Then
      Call Disable
    End If


  Application.EnableEvents = True
  
End Sub
 
Upvote 0
Many thanks to you both for replying.

I've tried both suggestions but neither work. I have code in Module1 that automatically refreshes the workbook every x secs and I use two command buttons that start and stop the refresh.

Module1

Dim SchedRecalc As Date


Sub Recalc()


With Sheet8.Range("A2")


.Value = Format(Time, "hh:mm:ss AM/PM")


End With


Call SetTime


End Sub


Sub SetTime()


SchedRecalc = Now + TimeValue("00:00:05")


Application.OnTime SchedRecalc, "Recalc"


End Sub


Sub Disable()


On Error Resume Next


Application.OnTime EarliestTime:=SchedRecalc, Procedure:="Recalc", Schedule:=False


End Sub




The command buttons work fine. Sub Disable stops the refresh when i press the command button assigned to a macro called Disable. What I am trying to do now is get the refresh to stop if "Stop" appears in A1 OR I press the command button. I thought that linking to the macro would do it but it doesn't.

Hope that makes sense. Any ideas to get this working?
 
Upvote 0

Forum statistics

Threads
1,213,491
Messages
6,113,963
Members
448,536
Latest member
CantExcel123

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