PDA

View Full Version : Using Yes No Message Box



clarksonneo
02-02-2011, 11:19 PM
Hi,

I don't understand how to use "Yes No Message Box".

What I need is:

After I run the Marco, a message box with a yes button and a no button will appear.

If I click Yes, the text in cell C3 will be deleted.
If I click No, the text in cell C3 will be not deleted.


Could you please write the marco for me?


What I need seem unnesscary to use marco, but the actual marco I am writing is not the one in this thread.

Thanks

mancubus
02-02-2011, 11:40 PM
try


Sub del()
response = MsgBox("question?", vbYesNo + vbQuestion, "title")
If response = vbYes Then
Range("C3").ClearContents
End If
End Sub

mancubus
02-02-2011, 11:42 PM
or



Sub dellll()
If MsgBox("question?", vbYesNo + vbQuestion, "title") = vbYes Then
Range("C3").ClearContents
End If
End Sub

JP2112
02-03-2011, 07:21 AM
or

Sub clearcell()
If CBool(vbNo - MsgBox("delete c3?", vbYesNo)) Then
Range("C3").ClearContents
End If
End Sub

shrivallabha
02-03-2011, 08:35 AM
Sub DeleteCellContent()

Dim Decision As VbMsgBoxResult

Decision = MsgBox("Do yo want to delete content in Cell C3?", vbYesNo, "DECIDE")
Select Case Decision
Case 6 'Yes case
Range("C3").ClearContents
Case 7 'No case
'Do nothing
End Select

End Sub

JP2112
02-03-2011, 09:12 AM
You could even turn mine into a one-liner (Rick Rothstein would be proud):


Sub clearcell()
If CBool(vbNo - MsgBox("delete c3?", vbYesNo)) Then Range("C3").ClearContents
End Sub

Kenneth Hobs
02-03-2011, 10:21 AM
If MsgBox("delete c3?", vbYesNo) = vbYes Then Range("C3").ClearContents