Be the first user to complete this post

  • 0
Add to List

Message Boxes in VBA Excel (Msgbox)

In VBA Excel Macro, Message Box (Msgbox) is one of the important features. Right from warning messages to calculated values in your code or anything. Whenever the code has something to communicate to the user, it can be done through Message box.

  • Open a new Excel WorkBook and press “Alt+F11” to open the Visual Basic Editor
  • Copy Paste the following code
Sub FnPainText
    Msgbox “Just A Plain Text”
End Sub
  • Run the Macro
Msgbox in Excel-1
Msgbox in Excel-1

Print Calculated Values in Message Box:

  • Open a new Excel WorkBook and press “Alt+F11” to open the Visual Basic Editor
  • Copy Paste the following 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 (Suppose you have put '11' and '13' in 'A1' and 'A2' cells respectively.)
Msgbox in Excel-2
Msgbox in Excel-2

Click here to read about 'Input Boxes in Excel Macro'



Also Read:

  1. VBA-Excel: Clear data from Excel Sheet(WorkSheet)
  2. VBA-Excel: Modified Consolidator – Merge or Combine Multiple Excel Files Into One Where Columns Are Not In Order
  3. VBA-Excel: Delete Blank Rows from Excel Work Sheet
  4. Excel-VBA : Open a Excel File using Another Excel File using Browse Option.
  5. VBA-Excel: Get all the WeekDays or Working days in Specified Date Range, (excluding Satudays and Sundays)