Question: I have a spreadsheet for scanning in serial numbers and asset tags.
2 Columns and a barcode scanner. I have setup conditional formatting so if any cell gets a duplicate entry in the set range it changes the font and cell color so its obvious a mistake was made.

I would like to play a sound when an error occurs to stop the need to keep looking back at the pc to see if a duplicate has been found.

I have found numerous ways to play a sound if a cell is a certain value but not if excels conditional formatting is applied.

Any suggestions would be appreciated.

```
#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 SoundMe() As String
'Updateby Extendoffice 20161223
    Call PlaySound("c:\windows\media\Speech On.wav", _
      0, SND_ASYNC Or SND_FILENAME)
    SoundMe = ""
End Function

```

and after the vb code 

Then save and close this code window, return to the worksheet, and enter this formula: =IF(A1>300,SoundMe(),"")into a blank cell beside the cell contains the value you want to play a sound based on, and then press Enter key, nothing will be displayed into the formula cell, see screenshot:

this works fine if a number is greater than or equals another I cant think how to get it to pick up a duplicate, Im very new to excel formulas.

Thankyou for any tips.

Answer: 
Here is the code with the condition `blnWannaHearDespasito = True`. And the music is *[Despasito](https://www.youtube.com/watch?v=kJQP7kiw5Fk)*. :)

```
Option Explicit

Public Sub TestMe()

    Dim blnWannaHearDespasito As Boolean
    blnWannaHearDespasito = True

    If blnWannaHearDespasito Then
        Application.Speech.Speak "Despasitoooooo"
    Else
        Application.Speech.Speak ("No")
    End If

End Sub

```

The `If blnWannaHearDespasito Then` is the same as `If blnWannaHearDespasito = True Then`, but it is shorter. The `If` is always evaluated to `True` or `False`.

[Speech.Speak Method in MSDN](https://msdn.microsoft.com/en-us/vba/excel-vba/articles/speech-speak-method-excel).
I do something similar, I enter in serial numbers and duplicates are an absolute no-no. Best way I've found to do this is to highlight the column that is being scanned into, go to `data>data validation` under settings select allow to custom then enter this formula
`=COUNTIF($F$2:$F$65536, F2)=1` where theres an F in the formula change that to the column letter that you are applying this to for example if scanning into A column then the formula would read `=COUNTIF($A$2:$A$65536, A2)=1` 
then when that is settled while still with the data validation window open click on the error alert tab, here you can set a custom message and alert. 
such as
Serial number already scanned!
This serial number has already been scanned into the system, please re-check the serial number and re-scan.
Not only will it pop up with an error when it finds a duplicate but will also play an audible default windows sound.