Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Message Boxes in VBA Excel (Msgbox)

In VBA Excel Macro, Mes­sage Box (Msg­box) is one of the impor­tant fea­tures. Right from warn­ing mes­sages to cal­cu­lated val­ues in your code or any­thing. When­ever the code has some­thing to com­mu­ni­cate to the user, it can be done through Mes­sage box.

  • Open a new Excel Work­Book and press “Alt+F11” to open the Visual Basic Editor
  • Copy Paste the fol­low­ing code
Sub FnPainText
    Msgbox “Just A Plain Text”
End Sub
  • Run the Macro

Msgbox in Excel-1

Msg­box in Excel-1



Print Cal­cu­lated Val­ues in Mes­sage Box:

  • Open a new Excel Work­Book and press “Alt+F11” to open the Visual Basic Editor
  • Copy Paste the fol­low­ing code
Sub FnSomeValues

    Dim mainworkBook as WorkBook
    Set mainWorkBook  = ActiveWorkBook
    intA = mainWorkBook.Sheets(1).Range(“A1”).Value
    intB = mainWorkBook.Sheets(1).Range(“A2”).Value
    intC = Cint(intA) + Cint(intB)
    MsgBox “The Addition of   “ & intA & “  and  “ & intB & “ is “ & intResult
 End Sub
  • Run the Macro (Sup­pose you have put ‘11’ and ‘13’ in ‘A1’ and ‘A2’ cells respectively.)
Msgbox in Excel-2

Msg­box in Excel-2

Click here to read about ‘Input Boxes in Excel Macro’

 

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: