Create a Message Box with VBA : MsgBox
Using VBA you can create a message box informing the user of something or asking him to perform something.
The Message Box is a dialog box create in Excel VBA and it looks like all the message boxes you have ever seen. For example here.
This message box was create by creating in your macro the following Visual Basic code
MsgBox "Hello this is a message box"
A critical message can be create with the following code. A VBA critical message will include the critical logo.
MsgBox "Hello this is a message box", vbCritical, "this is a title"
To enter a longer message like on 2 lines, enter the following code:
MsgBox "First Line" & vbNewLine & "Second Line"
MsgBox "welcome to Excel Made Easy" & vbNewLine & "the value of cell A1 is " & Range("A1"), vbOKCancel, "This is the title of the message box"
MsgBox "Do you want to marry me me", vbYesNoCancel + vbQuestions, "the big Question"
MsgBox "Do you want to marry me", vbYesNoCancel + vbDefaultButton1 + vbCritical
Dim response As Integer
response = MsgBox("Do you want to marry me", vbYesNo + vbQuestion, "The big question")
'this puts the value of the answer in the variable response'
If response = vbYes Then
'we test the response if it is a YES or a NO and write the value in cell A35
Range("a35").Value = "Oh my Love, I will be yours for ever"
Range("a35").Value = "Why, such a cruel world, you were the Love of my life"