Message box based on the value of a cell

M

MichaelRLanier

I would like to have multiple message boxes popup on a worksheet as
needed, each according to the value of a single cell. For example, if
A1=1, then the first message box will contain a brief message. If
A1=2, then the second and different message would appear. As long as
A1=0, no message would appear. I need an OK button to discontinue the
message box, but it would be better still if the box could be timed
for 5 or 6 seconds instead of having to rely on an OK button. It
would have to be made to appear only once or until the value of the
cell once again required its execution. Can anyone offer a macro?
Thanks.

Michael
 
G

Gord Dibben

Private Sub Worksheet_Calculate()
With Me.Range("A1")
If IsNumeric(.Value) Then
Select Case .Value
Case Is = 1
MsgBox "A1 is equal to 1"
Case Is = 2
MsgBox "A1 is equal to 2"
End Select
End If
End With
End Sub

Add more "cases" to suit.

This is sheet event code. Right-click on the sheet tab and "View Code"

Copy/paste the code into that sheet module.

Also assumes the value in A1 is a calculated value.

If manually entered change Private Sub Worksheet_Calculate() to

Private Sub Worksheet_Change(ByVal Target As Range)


Gord Dibben MS Excel MVP
 

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