call macro based on cell value vba

rohan85

Board Regular
Joined
Jun 27, 2013
Messages
81
hi I am trying to call a macro of running clock based on cell value could you plz assist as iam unable to run the
Private Sub Worksheet Change(ByVal Target As Range) when I debug it does not move after
Private Sub Worksheet Change(ByVal Target As Range) many thanks :) plz find the below code

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

lrow = ActiveSheet.Range("A121").End(xlUp).Offset(1, 0).Row

 If Not Intersect(Target, ActiveSheet.Range("D" & lrow)) Is Nothing Then
 If Target.Value = "Complete" Then Application.Run "runClock"
End If
End Sub


global clockOn As Boolean

Sub runClock()
 Range("A1").Value = Now()
If clockOn = True Then
 Application.OnTime Now + TimeValue("00:00:01"), "runClock"

End If
End Sub

Sub startClock ()
 clockOn=True
runClock
End Sub

Sub stopClock()
clockOn=False
End Sub
 
Last edited:

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi,
Not sure what you want to achieve but the following code will work fine.

Code:
Public clockOn As Boolean
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False


lrow = ActiveSheet.Range("A121").End(xlUp).Offset(1, 0).Row


 If Not Intersect(Target, ActiveSheet.Range("D" & lrow)) Is Nothing Then
 If Target.Value = "Complete" Then Call runClock
End If


Application.EnableEvents = True


End Sub




Sub runClock()
 Range("A1").Value = Now()
If clockOn = True Then
 Application.OnTime Now + TimeValue("00:00:01"), "runClock"


End If
End Sub


Sub startClock()
 clockOn = True
runClock
End Sub


Sub stopClock()
clockOn = False
End Sub

Hope it helps!
 
Upvote 0
hi thanks for yur help. I googled and found the below code. this is pasted in sheet1

it works till start time but when it comes to end iam not able to call the macro
Code:
Dim SchedRecalc As Date
 
Sub Recalc()
Dim lrow As Long

lrow = ActiveSheet.Range("a121").End(xlUp).Row


With Sheets("Data").Range("f" & lrow)
.Value = Format(Time, "hh:mm:ss AM/PM")
End With
Call SetTime
 
End Sub
 
Sub SetTime()
 
SchedRecalc = Now + TimeValue("00:00:10") 
Application.OnTime SchedRecalc, "Recalc"
 
End Sub
 

Sub Disable()
 
On Error Resume Next
 
Application.OnTime EarliestTime:=SchedRecalc, Procedure:="Recalc", Schedule:=False
 
End Sub

further iam trying to call the macros from a module using the below code but unable to call the macro disable it does not work

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim lrow As Long

lrow = ActiveSheet.Range("A121").End(xlUp).Row
       
    If Range("e" & lrow) = "O" Then
   Call SetTime
    
    
    If Range("e" & lrow) = "C" Then
   Call Disable
   
   

    End If
    End If
End Sub
 
Upvote 0
hi, thanks so much for yur previous code it works fine I have used your code thanks a lot :)
 
Upvote 0

Forum statistics

Threads
1,216,762
Messages
6,132,578
Members
449,737
Latest member
naes

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