Edit VBA

G

Gerard Sanchez

'Hi

'Below is a code given to me by one of the many good people around here
replaced with "=" instead of "<>".
'Question is that I only need to be notified ONCE that cell B72 and B73 are
equal (not when both are blank or zero )
'because right now my worksheet keeps chiming anytime I input any value
anywhere even when both mentioned cells are both blank.

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

Private Sub Worksheet_Calculate()
If Me.Range("B72").Value = Me.Range("B73") Then
sndPlaySound32 "chimes", 1&
End If
End Sub


'Please help
 
P

Per Jessen

Hi

Try this:

Private Sub Worksheet_Calculate()
If Me.Range("B72") = "" Or Me.Range("B72") = 0 Then Exit Sub
If Me.Range("B72").Value = Me.Range("B73") Then
sndPlaySound32 "chimes", 1&
End If
End Sub

Regards,
Per
 
G

Gerard Sanchez

Tried this code,

Problem solved for the zero and blank values,
but only thing is that it didn't address that when B72=B73,

chime should only play once.

Is there any way to intruct it to play chime only once?

Thanks!
 
B

Bob Phillips

Private Sub Worksheet_Calculate()
Static OnlyOnce As Boolean

If OnlyOnce Then Exit Sub
If Me.Range("B72").Value = "" Or Me.Range("B72").Value = 0 Then Exit Sub
If Me.Range("B72").Value = Me.Range("B73") Then
sndPlaySound32 "chimes", 1&
OnlyOnce = True
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top