Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Alarm in excel based on computer time

0

Hello i am quite new in excel but willing to learn , 

i am a  forex trader by occupation , and i have a specific need in the excel format , hopefully the long time members here could help me out ,

so the thing is this , 
the times iin the cells are inserted manually by me 

what i would like to have is for excel to pop up a message and beep sound whenever the specific time in the cell matches with the time in my computer

i hope the below pic would make what i mean more clearer 


i thank you in advance for any inputs you might have ,,

EDIT:(thank you John R.U)
 when say the time of the day is 8:01 ,there is an alert, 

ex: so when there is an alarm, all i have to do is see the excel cells to see which currency i must focus on.

PS: (it would be even more better if the cell itself changes color )

as there might be instances that different currency pairs have the same time. so the time itself is the most optimum option here

regards ,

Jimz

Answer
Discuss

Discussion

Hi Jimz and welcome to the Forum

I'm not clear what you want here. Do you mean you want an alert for "XAUUSD" say when the time of day becomes 08:01, then 11:03 then 14:05 etc. (plus the same for the other foreign exchange pairs)?

Please edit your original question to clarify.
John_Ru (rep: 6142) Dec 14, '21 at 8:22 am
Thank you for your warm welcome ,,   Yes this is exactly what i mean ,
when the time of the day is 8:01 there is an alert and then the same as with the others  ex: when there is an alarm, all i have to do is see the excel cells to see which currency i must focus on. PS: (it would be even more better if the cell itself changes color ) as there might be instances that different currency pairs have the same time. so the time itself is the most optimum option here. thank you
jjeeww Dec 14, '21 at 10:55 pm
Thanks for the clarification Jimz. I'm busy at present but hope to provide a working sheet later in my day. It will involve VBA but I'll outline how it works. 
John_Ru (rep: 6142) Dec 15, '21 at 6:03 am
Jimz- my Answer below is quite complicated but hopefully shows the power of VBA (Excel's built-in programming language). I guess you'll struggle to understand it since you're so new to Excel but can make practical use of it. Keep following Don's tutorials (on this site, the newsletters and YouTube) and it will make sense in time!
John_Ru (rep: 6142) Dec 16, '21 at 12:02 pm
Does the Answer/file work for you? 
John_Ru (rep: 6142) Dec 20, '21 at 7:40 am
Add to Discussion

Answers

0

Jimz

In the revised sheet attached, all the cells in A4:F12 have data validation so only times (in the format 00:00:00) can be entered- you had mixed fomats - so that they can be compared with the VBA variable Time (= local system time). Formatting has been changed to show seconds too (although that isn't necessary for the code to work).

You'll see B1 is the current time- that will start to count when the green "Start timer..." button is pressed. That calls up this macro (with comments):

Sub StartTimer()

InitAlrms 'clear formatting and load alarms
SetTime ' start the timer
End Sub
which first calls this macro:
Sub InitAlrms()
With Range("A3").CurrentRegion
    ReDim Alrms(1 To .Rows.Count, 1 To .Columns.Count)
    For m = 1 To UBound(Alrms, 1)
        For n = 1 To UBound(Alrms, 2)
            With Range("A3").Offset(m - 1, n - 1)
                Alrms(m, n) = .Value
                If m > 1 Then .Interior.Color = 16777215
            End With
        Next n
    Next m
End With

End Sub
which loads the alarm times (currently in B4:F12) plus the column headings into an array so it can be checked quickly (every second).Note you could add another row or column (to get even more alarms) and the macro will adjust but you need to bear in mind the red warning (currently in A14).

Then this macro is called which starts the timer- it updates the time in cell B1 and calls itself again (every second). Importantly it first calls the macro in bold:

Sub SetTime()

CheckAlrms 'see if alarms need displaying

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

Application.OnTime SchedRecalc, "SetTime" 'retrigger
Sheet1.Range("B1").Value = Time 'update time

End Sub
That's this macro below, which runs through the array (which was loaded before) and uses the test (in bold, over three split lines) to see if there's a valid time in the array cells and if it/they match the current sytsem time (or within 2 seconds of it). If so it calls in InitAlrms macro (to clear any cells set as red and) to made matching cells red. It also collects the associated column heading and gives a beep plus message of the alarm (or several alarms) which now show red instead whatever was set to red before (your old scheduled tasks):
Sub CheckAlrms()

Dim Mess As String, m As Long, n As Long, NewAlrm As Boolean

NewAlrm = False

For m = 2 To UBound(Alrms, 1)
    For n = 1 To UBound(Alrms, 2)
    With Range("A3").Offset(m - 1, n - 1)

        If IsEmpty(Alrms(m, n)) = False And _
        Time >= Alrms(m, n) And _
        Time < (Alrms(m, n) + TimeValue("00:00:02")) Then

            If NewAlrm = False Then InitAlrms
            NewAlrm = True ' set flag
            Mess = Mess & "Alarm: " & Alrms(1, n) & " from " & CDate(.Value) & vbLf
            .Interior.Color = vbRed
        End If
    End With
    Next n
Next m

If Mess <> "" Then
    Beep
    MsgBox Mess ' comment this out if alarms are <1 min apart
End If

End Sub
Note that the message box needs to be cleared (by clicking Ok) but you could comment that line out if you just rely on the red cells (which will indicate the latest task to be done).

The pinky button "Stop timer..." will clear B1 since it calls this macro:

Sub Reset()
Call Disable 'stop timer
Sheet1.Range("B1").Value = "" 'clear time
End Sub
The called Disable macro just stops the SetTime macro (see in file).

This should allow you to have lots of alarms in a day and see which task you should be working on. You can play around in cells F9:F12 to see how the messages and cell shading works (e.g. when you have two with the exact same time) if you want to leave your existing times unaffected. Use the Start... button when you change values so the array is re-loaded (that could be done automatically but I haven't done that).

Note that you'll need this file to be running (/visible) for it to update/ you to get alerts

Hope this fixes your problem.If so, kindly change your question title to "Multiple/ many daily alarms to alert work tasks/ priority" (which better describes the solution, for the guidance of other users).

Discuss

Discussion

Jimz. Did that work for you? 
John_Ru (rep: 6142) Dec 18, '21 at 4:07 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login