Excel in Curiosity
New Member
- Joined
- Sep 15, 2021
- Messages
- 9
- Office Version
- 2016
- Platform
- Windows
I am trying to run a macro when 2 cells have the same value, here's my code:
'---------------------------------------------------------------------------------------
Sub timer()
interval = Now + TimeValue("00:00:01")
If Range("F16").Value = 0 Then Exit Sub
Range("F16") = Range("F16") - TimeValue("00:00:01")
Application.OnTime interval, "timer"
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("F9") = Range("F10") Then
timer
End If
End Sub
'--------------------------------------------------------------------------------------
The macro is in sheet1. When cell F9 and cell F10 is equal, the timer falls straight to 0 (from 10 seconds [00:00:10 in F16] to 0 with NO 1-second interval)
But when I only run the Sub Timer() as a module, through the macro dialog box, the countdown works just fine.
What am I missing? Please help
'---------------------------------------------------------------------------------------
Sub timer()
interval = Now + TimeValue("00:00:01")
If Range("F16").Value = 0 Then Exit Sub
Range("F16") = Range("F16") - TimeValue("00:00:01")
Application.OnTime interval, "timer"
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("F9") = Range("F10") Then
timer
End If
End Sub
'--------------------------------------------------------------------------------------
Timer.xlsm | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | |||||||||
2 | |||||||||
3 | |||||||||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 | Value of A: | 12 | |||||||
10 | Value of B: | 12 | |||||||
11 | |||||||||
12 | |||||||||
13 | |||||||||
14 | |||||||||
15 | |||||||||
16 | Timer: | 00:00.0 | 0.00000000 | ||||||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
G16 | G16 | =F16 |
The macro is in sheet1. When cell F9 and cell F10 is equal, the timer falls straight to 0 (from 10 seconds [00:00:10 in F16] to 0 with NO 1-second interval)
But when I only run the Sub Timer() as a module, through the macro dialog box, the countdown works just fine.
What am I missing? Please help