How to Ring an Alarm in Excel
Would you like to hear an audio notification when your Excel data hits certain values? Here’s how to ring an alarm in Excel.
Excel spreadsheets allow you to quickly and easily see important values within your data. You can use conditional formatting in Excel, for example, to change the color of a cell depending on its value.
A visual indication is useful, but if the cell in question is on another sheet or off the edge of your current view, then you’re not going to notice the change. Wouldn’t it be useful if you could get Excel to make a sound when certain criteria are met?
The good news is that it is possible to do, although you’ll need to dip your toe into the world of Visual Basic to do so. Thankfully, you won’t need any programming skills to get this to work; you can simply copy and paste the code below.
Here’s how to ring an alarm in Excel.
How to Play a System Sound to Ring an Alarm in Excel
You can make Excel play a system sound with just a few lines of Visual Basic. You can then trigger this sound based on the value of a cell.
To play a system sound in Excel:
- Launch Microsoft Visual Basic for Applications by using the keyboard shortcut Alt+F11.
- Go to Insert > Module.
- Enter the following code:
Function MakeABeep() as String Beep MakeABeep = “” End Function
- Click the Save icon.
- Click on the Save as Type drop-down and select Excel Macro-Enabled Workbook. Your file needs to be saved in this format for the sound to play.
- Save your workbook.
- Close the Microsoft Visual Basic for Applications window by clicking the X in the top-right hand corner of the window.
- To test your beep, type the following into any cell: =MakeABeep()
- Press Enter, and you should hear a system sound.
How to Play a Custom Sound in Excel Using Visual Basic
You can also get Excel to play a specific sound file if you prefer to choose your own sound rather than playing the default system beep.
To play a custom sound in Excel:
- Launch Microsoft Visual Basic for Applications by pressing Alt+F11.
- Click Insert > Module.
- Enter the following code:
#If Win64 Then Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _ Alias "PlaySoundA" (ByVal lpszName As String, _ ByVal hModule As LongPtr, ByVal dwFlags As Long) As Boolean #Else Private Declare Function PlaySound Lib "winmm.dll" _ Alias "PlaySoundA" (ByVal lpszName As String, _ ByVal hModule As Long, ByVal dwFlags As Long) As Boolean #End If Const SND_SYNC = &H0 Const SND_ASYNC = &H1 Const SND_FILENAME = &H20000 Function AlarmSound() As String Call PlaySound("C:\Users\adam\Downloads\alarm.wav", _ 0, SND_ASYNC Or SND_FILENAME) AlarmSound = "" End Function
- Replace “C:\Users\adam\Downloads\alarm.wav” with the file location of the sound file you want to use. The easiest way to get the full file path is to navigate to the file in Windows Explorer, right-click on it, and select Copy as Path.
- Close the Microsoft Visual Basic for Applications window.
- Test your sound by typing the following into any cell: =AlarmSound()
- Press Enter, and your sound should play.
How to Trigger a Sound to Ring an Alarm in Excel
Now that you have set up your beep or alarm sound, the final stage is to trigger these sounds when needed. There are many different ways you can choose to trigger your alarm. Here is an example of how to use your sound in an IF statement.
To play an alarm when a value reaches a certain level:
- Select an empty cell.
- Type: =IF(
- Click the cell you want to monitor the value of.
- Type: > followed by the value you want to trigger the alarm.
- Now type a comma, then MakeaBeep() or AlarmSound().
- Type another comma, then type: “”)
- Press Enter.
Now when the cell you are monitoring exceeds the value you set, your alarm will sound. You can test this by typing a value above your threshold into the relevant cell.
Unleash the Power of Excel
Learning to ring an alarm in Excel requires you to use Visual Basic. Using Visual Basic allows you to get Excel to do things far beyond its usual scope. However, it requires a reasonable knowledge of the programming language and how it works with Excel.
Excel can do plenty of things without the need for using Visual Basic. You can record macros in Excel that will replay a series of actions. Once created, you can save your macros to use in other spreadsheets. You can also create Excel formulas using the many built-in functions in Excel, such as VLOOKUP, TRUNC, or any of the many other useful functions.
Peter
November 5, 2022 at 10:06 pm
Just tried this on one cell and it worked a treat. But when I did a group of cells in a single row it Beeped any time the cell vaule in question changed. Here is the orinianal formula, this will change from Yes to No if certain conditions are meet when covering a day shift =IF(MOD(COLUMNS(G:G)-1,4)1,”Yes”,”No”),””) These formulars are in rows E and F and in the row below (row F) I just change the D for N for night shifts. The formular to Make a Beep is =IF(E16=”No”,MakeABeep(),””) This will give an alarm if the shift is not covered. But when I grouped a row of cells as a test I used =IF(E16:W16=”No”,MakeABeep(),””) and the Beep sounds at any change in value. These are in a different cell as I could not nest it into the main formular, love to Know how to do that too. So how can i stop the alarm from Beeping when ever the cell vaule in rows E and F change. Thanks in advance.
Roel Panis
November 20, 2023 at 12:48 am
Hi Adam,
What you have shared is very useful! I did it and worked well!
Thank you very much