ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   How do I run a Macro on basic of a value in a specific cell (https://www.excelbanter.com/excel-worksheet-functions/22281-how-do-i-run-macro-basic-value-specific-cell.html)

Steen H. Pedersen

How do I run a Macro on basic of a value in a specific cell
 
ex.:
If A2=1 then run Macro "GetTime1"

Steen H. Pedersen

Sorry -I forgot:
The Macro "GetTime" shuld copy a range of cells and place them at the row
where the Macro is called from

"Steen H. Pedersen" skrev:

ex.:
If A2=1 then run Macro "GetTime1"


Fadi Chalouhi

Insert the following code in the worksheet_change macro of the relevant
worksheet :
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$2" And Target.Value = "1" Then
' Run your macro
End If
End Sub

This assumes the following :
(1) the cell you are monitoring is A2 (make sure you put the $ in the
address)
(2) the value you are monitoring is 1
(3) you only want your macro to run when cell A2 gets modified to 1.
(4) if you want your macro to run every time anything changes in the
worksheet (and when cell A2 is 1) then remove the Target.Address
condition.

HTH

Fadi
www.chalouhis.com/XLBLOG


Steen H. Pedersen

Thank You
This got me "over the hill"

Steen

"Fadi Chalouhi" skrev:

Insert the following code in the worksheet_change macro of the relevant
worksheet :
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$2" And Target.Value = "1" Then
' Run your macro
End If
End Sub

This assumes the following :
(1) the cell you are monitoring is A2 (make sure you put the $ in the
address)
(2) the value you are monitoring is 1
(3) you only want your macro to run when cell A2 gets modified to 1.
(4) if you want your macro to run every time anything changes in the
worksheet (and when cell A2 is 1) then remove the Target.Address
condition.

HTH

Fadi
www.chalouhis.com/XLBLOG




All times are GMT +1. The time now is 02:11 AM.

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