MarkReddell
Board Regular
- Joined
- Sep 1, 2011
- Messages
- 210
- Office Version
- 365
- Platform
- Windows
- Mobile
Does anyone know how to start a macro based on a cells value??? Thx.
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
If ThisWorkbook.ActiveSheet.Cells(2, 2).Value = 2 Then '<<<--- Cell B2 is defined and its value - modify them to suit your needs
Call Your_Macro_to_be_run '<<<--- Modify this to suit your needs, make sure the macro runs smoothly
End If
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$A$1" Then Exit Sub 'change address to the cell that you're interested in
'If the value is the result of a formula, use the address(es) of the cells that are inputs to the formula
If Range("A1").Value = "testValue" Then 'replace testValue with the value that will trigger the rest of the macro
'Code goes here when cell A1 has the value of interest
MsgBox "hello"
End If
End Sub
Thx. for your help!!! Question: If A1=0 or "", How would invoke a macro that aleady exits? Thanx 4 your help!!!!Hello Mark,
Read carefully below code, adapt it to your needs and insert it in the module of the sheet where target cell is hosted.
Code:Private Sub Worksheet_Calculate() Application.EnableEvents = False If ThisWorkbook.ActiveSheet.Cells(2, 2).Value = 2 Then '<<<--- Cell B2 is defined and its value - modify them to suit your needs Call Your_Macro_to_be_run '<<<--- Modify this to suit your needs, make sure the macro runs smoothly End If Application.EnableEvents = True End Sub
Please confirm this solution solves your problem, as expected. Thank you.
Romulus.