Column A <= Column B then play sound

sheeplvl1

New Member
Joined
Apr 7, 2011
Messages
2
Hi everyone,

This is my first post. Please help me on this play sound problem

I am trying to compare cell values in column A with cell values in column B.

The idea is if B1 is <= C1 then play a sound file
and I want to do it all the way down to wherever I want since I'm trying to use this Macro to track Stocks I am watching and the list my grow or reduce anytime.

I found some great codes on graemeal's post about "Playing a sound on cell value" and try to modify it but have no luck to get it work.
Here's the original macro provided by VoG

Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Private Sub Worksheet_Calculate()
Const FName As String = "C:\Intel.wav"
Dim c As Range
For Each c In Range("F2:F6")
If c.Value >= 1 Then
Call PlaySound(FName, 0&, SND_ASYNC Or SND_FILENAME)
Exit Sub
End If
Next c
End Sub

Here's my mod which doesn't work :eeek: (Modifications are in red)

Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Private Sub Worksheet_Calculate()
Const FName As String = "C:\Intel.wav"
Dim c As Range
Dim d As Range
For Each c In Range("B5:B16")
For Each d In Range("C5:C16")
If c.Value <= d.Value Then
Call PlaySound(FName, 0&, SND_ASYNC Or SND_FILENAME)
Exit Sub
End If
Next
Next
End Sub

Can someone plz tell me what i did wrong? I would really appreciate the help as I've been looking for the answer for the past month.
 
Last edited:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Here's the code with its formats...with mods in red again

Code:
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long
 
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Private Sub Worksheet_Calculate()
Const FName As String = "C:\Intel.wav"
Dim c As Range
For Each c In Range("F2:F6")
    If c.Value >= 1 Then
        Call PlaySound(FName, 0&, SND_ASYNC Or SND_FILENAME)
        Exit Sub
    End If
Next c
End Sub

Code:
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long
 
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Private Sub Worksheet_Calculate()
Const FName As String = "C:\Intel.wav"
Dim c As Range
[COLOR="Red"]Dim d As Range[/COLOR]
For Each c In Range("B5:B16")
[COLOR="red"]For Each d In Range("C5:C16")[/COLOR]
    If c.Value [COLOR="red"]<= d.Value[/COLOR] Then
        Call PlaySound(FName, 0&, SND_ASYNC Or SND_FILENAME)
        Exit Sub
    End If
Next
[COLOR="red"]Next[/COLOR]
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,866
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top