Help with MsgBox...

T

tjb

When the user selects the number 350 from a list validated cell or enters 350
into a list validated cell I want to use MsgBox or a UserForm to display a
message. On the MsgBox or UserForm I want two options, OK and another button
that will clear the entry of 350 from the cell, like a Cancel button or
something along those lines. Thanks!
 
H

Harald Staff

Hi

Macro work. Rightclick the sheet tab, choose View code, paste this in:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target(1).Value = 350 Then
If MsgBox("350 -you mean for real ?", vbYesNo + vbQuestion) = vbNo Then
Target(1).Value = ""
End If
End If
End Sub

HTH. Best wishes Harald
 
T

tjb

This is good except for I need the warning to occur when 350 is entered in a
specific cell, not any cell on the worksheet. Any suggestions?
 
D

Dave Peterson

You can modify Harald's suggested code to check for a range first:

Private Sub Worksheet_Change(ByVal Target As Range)

if intersect(target(1),me.range("a1")) is nothing then exit sub

If Target(1).Value = 350 Then
If MsgBox("350 -you mean for real ?", vbYesNo + vbQuestion) = vbNo Then
Target(1).Value = ""
End If
End If
End Sub

Or even check a complete column with something like:

if intersect(target(1),me.range("a:a")) is nothing then exit 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