ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   message box keeps popping (https://www.excelbanter.com/excel-programming/423799-message-box-keeps-popping.html)

Amelia

message box keeps popping
 
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!

OssieMac

message box keeps popping
 
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.
--
Regards,

OssieMac


"amelia" wrote:

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!


Patrick Molloy[_2_]

message box keeps popping
 
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


"amelia" wrote:

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!


curlydave

message box keeps popping
 
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

Amelia

message box keeps popping
 
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!

"CurlyDave" wrote:

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



All times are GMT +1. The time now is 12:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com