message box keeps popping

A

amelia

I would like to make the message box pop automatically when cell G24="pop".
But the message keeps popping when i click to anywhere in the worksheet.

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Range("G24").Value = "pop" Then
Msg = MsgBox("Both Values do not agree", vbOKOnly)
End If
End Sub

Thanks for any help!
 
O

OssieMac

Hi Amelia,

Not certain that I really understand what you are trying to achieve.The code
you have will run every time you select a cell. It needs to be controlled so
therefore need to know what cell to be selected to fire the code. Also not
sure that Selection event is correct. Maybe should be Change event.

Do you want the code to run every time you select Cell G24?
or do you want it to run every time you change some other cell that caused
G24 to change to pop. If the latter, then what is the formula in G24? (That
tells me what other cell/s are being changed to return pop in G24.)

If none of the above then see if you can explain the problem a little more.
 
P

Patrick Molloy

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Range("G24").Value = "pop" Then
Msg = MsgBox("Both Values do not agree", vbOKOnly)
Range("G24")=""
End If
End Sub
 
C

CurlyDave

You don't Mention how G24 Becomes the Word "pop"
If you are manually change the cell then try

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$G$24" Then
If Target = "pop" Then Msg = MsgBox("Both Values do not
agree", vbOKOnly)
End If
End Sub

If the cell changes by calculation then try this

Private Sub Worksheet_Calculate()
Dim r As Range
Set r = Range("G24")
If r = "pop" Then Msg = MsgBox("Both Values do not agree",
vbOKOnly)

End Sub
 
A

amelia

It works now, ive used curly dave's 2nd solution. My bad, should have
explained clearer. By the way, thanks for the help u all!
 

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