Link to home
Start Free TrialLog in
Avatar of Unreal1998
Unreal1998

asked on

Excel Message Box dependent on cell value

I have a list on cell B3 and I want a message to appear every time a certain value is selected. For example:

On cell value change

 IF B3="JUSTIN B" then show message "RUN FOR YOUR LIFE!"

Lastly, can I duplicate this macro for multiple cell values and show other messages.

For example:

 IF B3="JUSTIN B" then show message "RUN FOR YOUR LIFE!"

 IF B4="Y" then show message "Complete Question on Cell G7!" And so forth...
ASKER CERTIFIED SOLUTION
Avatar of javaftper
javaftper
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can add as many IF statements as you like, eg-

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Range("B3").Value = "JUSTIN B" Then
    MsgBox "RUN FOR YOUR LIFE!"
End If

If Range("B4").Value = "Y" Then
    MsgBox "Complete Question on Cell G7!"
End If

End Sub
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It's not the SelectionChange but Change event which you need, otherwise the test and message will pop up every time any cell is selected.

In my code, it is also checked whether one of the trigger cell is changed, a necessary condition.

In my example, I have showed 2 empty conditions, for you to play around and extend.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The MsgBox spawning message was intended for javatper's code, not calacuccia's. Calacuccia's seems to be pretty much like mine, only I'd like to think that my If statements are prettier :D
Other event my friend :-)
Actually, I wanted Worksheet_Change too, cause that's what makes sense. I had assumed javatper's was that one and I copied/pasted without noticing :P
Oops..  Misread the question and went off and did my own thing.  Ignore.

Matt
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Unreal1998
Unreal1998

ASKER

Great! Too bad I could not give 500 points to all.