Microsoft Excel includes several built-in tools that allow users to automate conditional formatting (like changing the color of a cell) depending on whether specific conditions are met.

But many people don’t realize it’s possible to make Excel play a sound using Microsoft’s Visual Basic for Applications (VBA). This Excel tutorial will explain how to sound an alarm in Excel when a condition is met.

Table of Contents
    How to Create and Ring a Sound Alarm in Microsoft Excel image 1

    How to Ring an Alarm in Excel

    Two steps are involved in getting Excel to play a sound based on a particular trigger. First, you must add custom code enabling Excel to play the sound. Then, you need to tell Excel what event or value will trigger the sound.

    To do this, you must create a new rule using an Excel VBA macro. This sounds complicated, but don’t worry—all you need to do is copy and paste the code below and then change some basic parameters.

    How to Create an Alarm in Excel

    1. Open your Excel spreadsheet.
    2. Press Alt + F11 to open the pop-up Microsoft Visual Basic for Applications window.
    3. Click Insert > Module.
    How to Create and Ring a Sound Alarm in Microsoft Excel image 2
    1. Enter the following code:

    Function MakeABeep() as String

    Beep

    MakeABeep = “”

    End Function

    How to Create and Ring a Sound Alarm in Microsoft Excel image 3
    1. Click Save.
    How to Create and Ring a Sound Alarm in Microsoft Excel image 4
    1. In the Save as Type drop-down menu, select Excel Macro-Enabled Workbook.
    How to Create and Ring a Sound Alarm in Microsoft Excel image 5
    1. In any cell, type “=MakeABeep()” and press Enter. If you hear a system sound, your code has worked, and it’s time to move on to the next step.
    How to Create and Ring a Sound Alarm in Microsoft Excel image 6

    How to Trigger the Alarm in Excel

    Next, you need to add conditional formatting to the cell you would like to play a sound upon a specific event. This will depend on what you want the trigger to be, so you might need to know how to use the various Excel formulas to make it work exactly as planned.

    Here’s a basic example showing how to get cell A1 to play a sound if it reaches 100:

    1. Select an empty cell in your Excel worksheet.
    2. Type “=IF(A1>100, MakeABeep(),””)” and press Enter.
    How to Create and Ring a Sound Alarm in Microsoft Excel image 7

    When the A1 cell value reaches 101, a system sound will play.

    How to Get Excel to Play a Custom Sound

    You can get Excel to play multiple custom sounds rather than relying on the single system sound. This way, you can set up multiple alarms to ring when different conditions are met.

    1. Open your Excel file.
    2. Press Alt + F11 to open Microsoft VBA.
    3. Press Insert > Module.
    How to Create and Ring a Sound Alarm in Microsoft Excel image 8
    1. In the dialog box, type:

    #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:UsersUserDownloadssound.wav”, _

    0, SND_ASYNC Or SND_FILENAME)

    AlarmSound = “”

    End Function

    How to Create and Ring a Sound Alarm in Microsoft Excel image 9
    1. Replace “C:UsersUserDownloadssound.wav” with the location of the sound file that you would like to use. To get this, open the folder in File Explorer, right-click the address bar, and select Copy address as text.
    How to Create and Ring a Sound Alarm in Microsoft Excel image 10
    1. Press Ctrl + S to save the file.
    2. In the Save as Type drop-down list, select Excel Macro-Enabled Workbook.
    How to Create and Ring a Sound Alarm in Microsoft Excel image 11
    1. In any blank cell, add your conditional formatting equation. For example, “=IF(A1>100, AlarmSound(),””)”. As above, this will cause an alarm to play if the A1 cell reaches the value of 100.
    How to Create and Ring a Sound Alarm in Microsoft Excel image 12

    Note: In this template code, “AlarmSound” was used instead of “MakeABeep.” Both of these can be written as whatever you would like. For example, if you wanted multiple alarms to ring for different conditions, you could use “Alarm1,” “Alarm2,” and so on.

    What Kind of Alarms Can You Create in Excel?

    Excel is a powerful tool, and it includes several formulas you can use to format your data exactly how you want it. To use these rules, click the Home tab and click Conditional Formatting.

    How to Create and Ring a Sound Alarm in Microsoft Excel image 13

    Here are a few examples of data conditions that you can tell Excel to play an alarm for:

    1. If the value is equal to, greater than, lesser than, or between another value(s)
    2. If the cell is a duplicate
    3. If the cell refers to a particular date (like a due date or expiration date)
    4. If the value is in a specific percentile (for example, the top 10% or above average)
    5. If the cell is a particular color—useful when you have previous conditional formatting rules set up

    Data Management Has Never Been Easier

    Microsoft Office’s Excel is one of the most powerful data validation and analysis tools on the market and has been for a long time. Whether you want your Excel workbook to display your data in an easy-to-understand manner or format cells to notify you when conditions are met, Excel has the tools for you.

    Leave a Reply

    Your email address will not be published. Required fields are marked *