Specific change using Worksheet_Change

NoobishNewb

New Member
Joined
Jun 1, 2018
Messages
3
Hi all,

I would like to know how to make excel play a sound when a specific change occurs.

For example, I have a range of cells (F6 to F50) with formula within the cells. They are blank at first (which is normal). When the stock market moves, some of the cells (say F8 and F25) are "Triggered" based on the formula and play a sound accordingly. As the price of the stock changes, cell F8 changes from "Triggered" back to blank. However, because F25 still remains as "Triggered", excel plays a sound again.

I would like excel to play a sound when the cell changes from blank to "Triggered". But when the cell changes from "Triggered" back to blank, there should not be a sound even though there are other cells within F6 to F50 with the word "Triggered".

Please see below for what I have tried. (Btw I am a newbie in VBA).
Thanks!


Private Sub Worksheet_Change(ByVal Target As Range)


Dim Cell As Range
Dim CheckRange As Range
Dim PlaySound As Boolean


Set CheckRange = Range("F6:F50")


If Not Intersect(Target, CheckRange) Is Nothing Then


For Each Cell In CheckRange
If Cell.Value = "Triggered" Then
PlaySound = True
End If
Next


If PlaySound Then
Call PlayTrigger
End If

End If


End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I would like excel to play a sound when the cell changes from blank to "Triggered". But when the cell changes from "Triggered" back to blank, there should not be a sound
Try something like this:

Switch trigger to OFF

put this as 1st line of Worksheet_Change macro
Code:
Application.EnableEvents = False
Switch trigger to ON
then AFTER the line changing the value back to blank (last line of macro should work)
Code:
Application.EnableEvents = True
 
Last edited:
Upvote 0
Hi Yongle,

Not sure where exactly to put the codes. There is no line to change the value back to blank. It happens when the price changes and the formula is in the cell itself.
And also by putting the Application.EnableEvents = False at the first line, there is no sound when the trigger happens.
Please kindly advise.

Thanks!

Try something like this:

Switch trigger to OFF

put this as 1st line of Worksheet_Change macro
Code:
Application.EnableEvents = False
Switch trigger to ON
then AFTER the line changing the value back to blank (last line of macro should work)
Code:
Application.EnableEvents = True
 
Upvote 0
Switch trigger to OFF after line
Code:
Next

Switch trigger to ON as last line of macro
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,521
Messages
6,125,305
Members
449,218
Latest member
Excel Master

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