Consulting

Results 1 to 7 of 7

Thread: Solved: Make a Sound When a Cell is Changed to a Certain Value

  1. #1
    VBAX Newbie
    Joined
    Sep 2010
    Posts
    5
    Location

    Solved: Make a Sound When a Cell is Changed to a Certain Value

    This is the same title as a post by DRJ.

    When I enter the code in an open spreadsheet it works fine, however, after saving, exiting and then reloading it doesn't work.

    I'm using Excel 2003 with W7.

    Thanks,

  2. #2
    VBAX Newbie
    Joined
    Sep 2010
    Posts
    5
    Location
    Here's the link to the DRJ post:

    www dot vbaexpress dot com / kb / getarticle.php?kb id=161

  3. #3
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Are you enabling macros? If you are not prompted when opening the workbook go to Tools | Macros | Security and set it to Medium.

  4. #4
    VBAX Newbie
    Joined
    Sep 2010
    Posts
    5
    Location
    Thanks, that did it. Solved.

  5. #5
    VBAX Newbie
    Joined
    Oct 2012
    Posts
    2
    Location
    i can get the code to work,but after i enter a value of 10 or more in the selected range, i get a ding in other cells no matter what the value is that i entered

  6. #6
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    Hi Jixy,

    It's better to start a new post with a new problem, especial as the OP has marked it solved. But to answer your question it will ding because any time you make a change anywhere it checks the selected range and finds a value greater than 10. If you only want a ding when you change a value to greater than 10 in that range you need to remove the loop and tweak the IF like so:

    [vba]Option Explicit

    Private Declare Function sndPlaySound32 Lib "winmm.dll" _
    Alias "sndPlaySoundA" (ByVal lpszSoundName _
    As String, ByVal uFlags As Long) As Long

    Private Sub Worksheet_Change(ByVal Target As Range)

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

    Set CheckRange = Range("D5:G25")
    If Not Intersect(Target, CheckRange) Is Nothing And Target.Value > 10 Then
    PlaySound = True
    End If
    If PlaySound Then
    Call sndPlaySound32("C:\windows\media\ding.wav", 1)
    End If

    End Sub[/vba]
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

  7. #7
    VBAX Newbie
    Joined
    Oct 2012
    Posts
    2
    Location
    I am so impressed and grateful that you took the time to respond to my inquiry. I'm still having problems pasting it into the "view code" tab of excel as only the last line of code shows up, but i'll try to figure that out. thanks for the code and the advice on posting...sincerely,jixy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •