{"id":6711,"date":"2023-05-24T16:24:34","date_gmt":"2023-05-24T16:24:34","guid":{"rendered":"https:\/\/www.bizinfograph.com\/resource\/?p=6711"},"modified":"2024-05-10T06:56:08","modified_gmt":"2024-05-10T06:56:08","slug":"how-to-use-vba-message-box-in-excel","status":"publish","type":"post","link":"https:\/\/www.bizinfograph.com\/resource\/how-to-use-vba-message-box-in-excel\/","title":{"rendered":"How to use VBA Message Box in Excel?"},"content":{"rendered":"<p>VBA Message Box in Excel is a powerful tool for communicating with users. By displaying messages, warnings, or prompts, it enhances user interaction and provides valuable feedback during macro execution. With customizable options such as button styles and icon types, the VBA Message Box offers flexibility in tailoring the user experience. It can be employed for various purposes, including error handling, input validation, and informational alerts. Whether you&#8217;re developing complex automation scripts or simple macros, integrating Message Boxes can greatly improve the usability and functionality of your Excel applications. So, leverage the VBA Message Box in Excel to streamline workflows, guide users, and ensure a smooth and intuitive interaction process.<\/p>\n<p><strong>This Content Covers:<\/strong><\/p>\n<ol>\n<li><a href=\"#what-is-an-excel-vba-message-box?\"><strong> What is an Excel VBA Message Box?<\/strong><\/a><\/li>\n<li><a href=\"#different-parts-of-an-excel-vba-message-box.\"><strong> Different Parts of an Excel VBA Message Box.<\/strong><\/a><\/li>\n<li><a href=\"#syntax-and-purpose-of-excel-vba-message-box.\"><strong> Syntax and Purpose of Excel VBA Message Box.<\/strong><\/a><\/li>\n<li><a href=\"#how-to-insert-a-vba-message-box-and-create-prompt-text?\"><strong> How to <\/strong><strong>Insert a VBA Message Box<\/strong><strong> and Create Prompt Text?<\/strong><\/a><\/li>\n<li><a href=\"#inserting-different-buttons-with-codes.\"><strong>Insert<\/strong><strong>ing Different Buttons with Codes.<\/strong><\/a>\n<ul>\n<li><strong>Ok and Cancel Buttons<\/strong><\/li>\n<li><strong>Yes and No Buttons<\/strong><\/li>\n<li><strong>Abort, Retry and Ignore Buttons<\/strong><\/li>\n<li><strong>Retry and Cancel Buttons<\/strong><\/li>\n<li><strong>Help Button with Other Buttons<\/strong><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#inserting-different-icons-with-codes.\"><strong>Insert<\/strong><strong>ing Different Icons with Codes.<\/strong><\/a>\n<ul>\n<li><strong>Critical Icon: <\/strong><\/li>\n<li><strong>Question Icon: <\/strong><\/li>\n<li><strong>Exclamation Icon: <\/strong><\/li>\n<li><strong>Information Icon<\/strong><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#how-to-customize-title-and-prompt-in-a-vba-message-box?\"><strong> How to Customize Title and Prompt in a VBA Message Box?<\/strong><\/a><\/li>\n<li><a href=\"#how-to-insert-multiple-lines-inside-the-prompt-using-line-break?\"><strong>How to Insert Multiple Lines inside the Prompt using Line Break?<\/strong><\/a><\/li>\n<li><a href=\"#vba-message-box-with-it-statement.\"><strong> VBA Message Box with IF Statement.<\/strong><\/a><\/li>\n<\/ol>\n<h2><strong id=\"what-is-an-excel-vba-message-box?\">1. What is an Excel VBA message Box?<\/strong><\/h2>\n<p>The Excel VBA message box is a function that displays a pop-up window with a message and allows the user to choose from various buttons to respond to the message. The MsgBox function is a useful tool for communicating with the user and requesting input or confirmation in VBA code.<\/p>\n<h2><strong id=\"different-parts-of-an-excel-vba-message-box.\">2. Different Parts of an Excel VBA Message Box.<\/strong><\/h2>\n<p>The Excel VBA Message Box has four basic parts in it,<\/p>\n<p><strong>Title-<\/strong> Usually, this is used to make clear what the message box is for. If you don&#8217;t specify anything, it shows the name of the application, in this example Microsoft Excel.<\/p>\n<p><strong>Prompt-<\/strong> The prompt is the part of a message box that displays the actual message. Messages or any sort of data can be typed in this space for display.<\/p>\n<p><strong>Button-<\/strong> The default button is OK, but you can change or customize it to show other buttons such as, Yes\/No, Retry\/Ignore etc.<\/p>\n<p><strong>Close Icon-<\/strong> The close icon is used to close the message box.<\/p>\n<h2><strong id=\"syntax-and-purpose-of-excel-vba-message-box.\">3. Syntax and Purpose of Excel VBA Message Box.<\/strong><\/h2>\n<p><strong>Syntax: <\/strong>MsgBox( prompt [, buttons ] [, title ] [, helpfile, context ] )<\/p>\n<p><strong>Purpose: <\/strong>The purpose of the VBA message box is to display information to the user and allow them to interact with it. It is a pop-up window that can be used to display a message, prompt the user for input, or ask them to confirm an action.<\/p>\n<h2><strong id=\"how-to-insert-a-vba-message-box-and-create-prompt-text?\">4. How to <\/strong><strong>Insert a VBA Message Box<\/strong><strong> and Create Prompt Text?<\/strong><\/h2>\n<p><strong>Step 1: <\/strong>Go to <a href=\"https:\/\/www.bizinfograph.com\/resource\/how-to-add-developer-tab-in-excel\/\" target=\"_blank\" rel=\"noopener\"><strong>Developer <\/strong>tab<\/a> and press <strong>Visual Basic<\/strong> option. Or you can also right click on the worksheet name and select <strong>View Code<\/strong> option.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-6712 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-1.png\" alt=\"VBA Message Box in Excel\" width=\"639\" height=\"185\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-1.png 639w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-1-300x87.png 300w\" sizes=\"(max-width: 639px) 100vw, 639px\" \/><\/p>\n<p><strong>OR<\/strong><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-6713 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-2.png\" alt=\"VBA Message Box in Excel\" width=\"395\" height=\"324\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-2.png 395w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-2-300x246.png 300w\" sizes=\"(max-width: 395px) 100vw, 395px\" \/><\/p>\n<p><strong>Step 2: <\/strong>Click on the <strong>Insert<\/strong> button and choose <strong>Module.<\/strong><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-6714 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-3.png\" alt=\"VBA Message Box in Excel\" width=\"482\" height=\"224\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-3.png 482w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-3-300x139.png 300w\" sizes=\"(max-width: 482px) 100vw, 482px\" \/><\/p>\n<p><strong>Step 3: <\/strong>Insert the below given code inside the module box and press <strong>RUN.<\/strong> Or press <strong>F5<\/strong> key to perform a run.<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Sub Simple_MsgBox()<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>MsgBox &#8220;Welcome to Excel 365&#8221;<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End Sub<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6715 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-4.png\" alt=\"VBA Message Box in Excel\" width=\"506\" height=\"291\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-4.png 506w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-4-300x173.png 300w\" sizes=\"(max-width: 506px) 100vw, 506px\" \/><\/p>\n<p><strong>Step 4: <\/strong>When you press RUN or F5 key, this msgbox will appear on your screen.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6716 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-5.png\" alt=\"VBA Message Box in Excel\" width=\"264\" height=\"238\" \/><\/p>\n<h2><strong id=\"inserting-different-buttons-with-codes.\">5. Insert<\/strong><strong>ing Different Buttons with Codes.<\/strong><\/h2>\n<p><strong>5.1 Ok and Cancel Buttons: <\/strong>Open the VBA Module and insert the following VBA code inside it. Press <strong>RUN <\/strong>button or<strong> F5<\/strong> key to perform a run.<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Sub MsgBoxOKCancel()<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>MsgBox &#8220;Do You Want To Continue?&#8221;, vbOKCancel<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End Sub<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6717 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-6.png\" alt=\"VBA Message Box in Excel\" width=\"312\" height=\"222\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-6.png 312w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-6-300x213.png 300w\" sizes=\"(max-width: 312px) 100vw, 312px\" \/><\/p>\n<p><strong>5.2 Yes and No Buttons: <\/strong>Use this code inside VBA module to generate these buttons.<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Sub MsgBoxYesN0()<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>MsgBox &#8220;Do You Want To Continue?&#8221;, vbYesNo<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End Sub<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6718 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-7.png\" alt=\"VBA Message Box in Excel\" width=\"316\" height=\"231\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-7.png 316w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-7-300x219.png 300w\" sizes=\"(max-width: 316px) 100vw, 316px\" \/><\/p>\n<p><strong>5.3 Abort, Retry and Ignore Buttons: <\/strong>Insert this code and press RUN button to generate this three-button prompt.<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Sub MsgBoxAbortRetryIgnore()<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>MsgBox &#8220;<\/strong><strong>Do You Still Want To Continue?&#8221;, vbAbortRetryIgnore<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End Sub<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6719 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-8.png\" alt=\"VBA Message Box in Excel\" width=\"340\" height=\"180\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-8.png 340w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-8-300x159.png 300w\" sizes=\"(max-width: 340px) 100vw, 340px\" \/><\/p>\n<p><strong>5.4 Retry and Cancel Buttons: <\/strong>This following code generate a prompt with Retry and Cancel buttons.<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Sub MsgBoxRetryCancel()<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>MsgBox &#8220;What To Do Next?&#8221;, vbRetryCancel<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End Sub<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6720 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-9.png\" alt=\"VBA Message Box in Excel\" width=\"308\" height=\"215\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-9.png 308w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-9-300x209.png 300w\" sizes=\"(max-width: 308px) 100vw, 308px\" \/><\/p>\n<p><strong>5.5 Help Button with Other Buttons: <\/strong>The &#8216;vbMsgBoxHelpButton&#8217; constant can be used to display the help button\u00a0along with other button constants.<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Sub MsgBoxRetryHelp()<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>MsgBox &#8220;What Should We Do Next?&#8221;, vbRetryCancel + vbMsgBoxHelpButton<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End Sub<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6721 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-10.png\" alt=\"VBA Message Box in Excel\" width=\"369\" height=\"193\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-10.png 369w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-10-300x157.png 300w\" sizes=\"(max-width: 369px) 100vw, 369px\" \/><\/p>\n<h2><strong id=\"inserting-different-icons-with-codes.\">6. Insert<\/strong><strong>ing Different Icons with Codes.<\/strong><\/h2>\n<p><strong>6.1 Critical Icon: <\/strong>This is the code for default Critical Icon. Insert this inside the VBA Module and press RUN to execute.<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Sub MsgBoxCriticalIcon()<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>MsgBox &#8220;This May Remove All Your Data&#8221;, vbCritical<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End Sub<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6722 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-11.png\" alt=\"VBA Message Box in Excel\" width=\"336\" height=\"224\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-11.png 336w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-11-300x200.png 300w\" sizes=\"(max-width: 336px) 100vw, 336px\" \/><\/p>\n<p>You can also use the critical icon with other button options with this code.<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Sub MsgBoxCriticalIcon()<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>MsgBox &#8220;This May Remove All Your Data. Still Continue?&#8221;, vbYesNo + vbCritical<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End Sub<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6723 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-12.png\" alt=\"VBA Message Box in Excel\" width=\"410\" height=\"204\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-12.png 410w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-12-300x149.png 300w\" sizes=\"(max-width: 410px) 100vw, 410px\" \/><\/p>\n<p><strong>6.2 Question Icon: <\/strong>This <strong>vbQuestion<\/strong> code is used to generate Question icon inside the prompt.<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Sub MsgBoxQuestionIcon()<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>MsgBox &#8220;Closing This Window Without Saving Will Delete Your Data. Do You Want To Continue?&#8221;, vbYesNo + vbQuestion<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End Sub<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6724 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-13.png\" alt=\"VBA Message Box in Excel\" width=\"480\" height=\"205\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-13.png 480w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-13-300x128.png 300w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/p>\n<p><strong>6.3 Exclamation Icon: <\/strong>Exclamation icon can be generated with this code.<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Sub MsgBoxExclamationIcon()<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>MsgBox &#8220;There Is An Error With This Function&#8221;, vbRetryCancel + vbExclamation<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End Sub<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6725 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-14.png\" alt=\"VBA Message Box in Excel\" width=\"358\" height=\"214\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-14.png 358w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-14-300x179.png 300w\" sizes=\"(max-width: 358px) 100vw, 358px\" \/><\/p>\n<p><strong>6.4 Information Icon: <\/strong>Insert the <strong>vbInformation <\/strong>code inside the module and press RUN.<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Sub MsgBoxInformationIcon()<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>MsgBox &#8220;Do You Want to Retry?&#8221;, vbYesNo + vbInformation<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End Sub<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6726 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-15.png\" alt=\"VBA Message Box in Excel\" width=\"322\" height=\"246\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-15.png 322w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-15-300x229.png 300w\" sizes=\"(max-width: 322px) 100vw, 322px\" \/><\/p>\n<h2><strong id=\"how-to-customize-title-and-prompt-in-a-vba-message-box?\">7. How to Customize Title and Prompt in a VBA Message Box?<\/strong><\/h2>\n<p><strong>Step 1: <\/strong>To customize the prompt, just change the text inside first <strong>(\u201c \u201c) <\/strong>and to change the tile of the message box, change the text inside second <strong>(\u201c \u201c). <\/strong>Then press <strong>RUN <\/strong>button after inserting the code inside VBA Module.<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Sub MsgBoxQuestionIcon()<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>MsgBox &#8220;Do you want to continue?&#8221;, vbYesNo + vbQuestion, &#8220;Confirmation&#8221;<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End Sub<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6727 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-16.png\" alt=\"VBA Message Box in Excel\" width=\"556\" height=\"284\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-16.png 556w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-16-300x153.png 300w\" sizes=\"(max-width: 556px) 100vw, 556px\" \/><\/p>\n<p><strong>Step 2: <\/strong>Then press <strong>RUN <\/strong>button after inserting the code inside VBA Module.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6728 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-17.png\" alt=\"VBA Message Box in Excel\" width=\"351\" height=\"245\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-17.png 351w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-17-300x209.png 300w\" sizes=\"(max-width: 351px) 100vw, 351px\" \/><\/p>\n<h2><strong id=\"how-to-insert-multiple-lines-inside-the-prompt-using-line-break?\">8. How to Insert Multiple Lines inside the Prompt using Line Break?<\/strong><\/h2>\n<p><strong>Step 1: <\/strong>Open the VBA Module and insert the below given code inside it.<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Sub YesorNoMultiline()<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>MsgBox &#8220;If you aggree to the terms and conditions, click &#8216;Yes'&#8221; &amp; vbNewLine &amp; &#8220;If you do not aggree to the terms and conditions, click &#8216;No'&#8221;, vbYesNo, &#8220;Terms &amp; Conditions Confirmation&#8221;<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End Sub<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6729 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-18.png\" alt=\"VBA Message Box in Excel\" width=\"641\" height=\"158\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-18.png 641w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-18-300x74.png 300w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><\/p>\n<p><strong>Step 2:<\/strong> Press <strong>RUN<\/strong> button or <strong>F5<\/strong> key.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6730 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-19.png\" alt=\"VBA Message Box in Excel\" width=\"435\" height=\"203\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-19.png 435w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-19-300x140.png 300w\" sizes=\"(max-width: 435px) 100vw, 435px\" \/><\/p>\n<h2><strong id=\"vba-message-box-with-it-statement.\">9. VBA Message Box with IF Statement.<\/strong><\/h2>\n<p>Now we will create a VBA message box which will have an IF statement in it. So, the outcome will be different for different selection.<\/p>\n<p><strong>Step 1: <\/strong>Insert this code inside VBA Module. The that we used here has an IF statement in it and it has Yes and No button arguments. Based on the selection, there are two different statements inside the IF result and Else. Now lets see how this works.<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Sub MsgBoxInformationIcon()<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Result = MsgBox(&#8220;Do you aggree with these terms and conditions?&#8221;, vbYesNo + vbQuestion, &#8220;Confirmation Tab&#8221;)<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>If Result = vbYes Then<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>MsgBox &#8220;Thank You For Confirming&#8221;, , &#8220;Confirmed&#8221;<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>Else: MsgBox &#8220;Sorry You Are Not Eligible For Our Survices&#8221;, , &#8220;Denied&#8221;<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End If<\/strong><\/span><\/p>\n<p style=\"padding-left: 40px;\"><span style=\"color: #333399;\"><strong>End Sub<\/strong><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6731 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-20.png\" alt=\"VBA Message Box in Excel\" width=\"583\" height=\"223\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-20.png 583w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-20-300x115.png 300w\" sizes=\"(max-width: 583px) 100vw, 583px\" \/><\/p>\n<p><strong>Step 2: <\/strong>When you press the RUN or F5 key the code is active and returns this initial message box which we named as Confirmation Tab inside the code. We also inserted this first Prompt text inside the code in the first section (Result).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6732 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-21.png\" alt=\"VBA Message Box in Excel\" width=\"431\" height=\"215\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-21.png 431w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-21-300x150.png 300w\" sizes=\"(max-width: 431px) 100vw, 431px\" \/><\/p>\n<p><strong>Step 3: <\/strong>If we press Yes then this prompt will pop-up because we set this inside the code in <strong>IF Result.<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6733 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-22.png\" alt=\"VBA Message Box in Excel\" width=\"313\" height=\"247\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-22.png 313w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-22-300x237.png 300w\" sizes=\"(max-width: 313px) 100vw, 313px\" \/><\/p>\n<p><strong>Step 4: <\/strong>If we select No then another message box will open. By using the IF statement, we can create a series of message boxes based on choices.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6734 size-full\" src=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-23.png\" alt=\"VBA Message Box in Excel\" width=\"425\" height=\"237\" srcset=\"https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-23.png 425w, https:\/\/www.bizinfograph.com\/resource\/wp-content\/uploads\/2023\/05\/VBA-Message-Box-23-300x167.png 300w\" sizes=\"(max-width: 425px) 100vw, 425px\" \/><\/p>\n<ul>\n<li><strong>Error Handling<\/strong>: Use Message Boxes to alert users about errors encountered during VBA macro execution, providing informative messages and suggestions for resolution.<\/li>\n<li><strong>Input Validation<\/strong>: Employ Message Boxes to validate user input, ensuring that only valid data is entered into Excel worksheets or forms.<\/li>\n<li><strong>Confirmation Dialogs<\/strong>: Utilize Message Boxes to prompt users for confirmation before executing critical actions, such as deleting data or saving changes.<\/li>\n<li><strong>Informational Alerts<\/strong>: Display Message Boxes to convey important information or updates to users, such as reminders about upcoming deadlines or system maintenance.<\/li>\n<li><strong>Debugging<\/strong>: Insert Message Boxes into VBA code to output variable values or execution statuses, aiding in debugging and troubleshooting processes.<\/li>\n<li><strong>Customized User Interaction<\/strong>: Customize Message Boxes with different button styles, icon types, and message formats to create a tailored user experience that matches your application&#8217;s requirements and branding.<\/li>\n<\/ul>\n<p>For ready-to-use Dashboard Templates:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.bizinfograph.com\/dashboard-templates#Finance\" target=\"_blank\" rel=\"noopener\">Financial Dashboards<\/a><\/li>\n<li><a href=\"https:\/\/www.bizinfograph.com\/dashboard-templates#Sales\" target=\"_blank\" rel=\"noopener\">Sales Dashboards<\/a><\/li>\n<li><a href=\"https:\/\/www.bizinfograph.com\/dashboard-templates#Human-Resource\" target=\"_blank\" rel=\"noopener\">HR Dashboards<\/a><\/li>\n<li><a href=\"https:\/\/www.executiveknowledge.org\/dashboard-templates\/35\" target=\"_blank\" rel=\"noopener\">Data Visualization Charts<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>VBA Message Box in Excel is a powerful tool for communicating with users. By displaying messages, warnings, or prompts, it enhances user interaction and provides valuable feedback during macro execution. With customizable options such as button styles and icon types, the VBA Message Box offers flexibility in tailoring the user experience. It can be employed &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.bizinfograph.com\/resource\/how-to-use-vba-message-box-in-excel\/\"> <span class=\"screen-reader-text\">How to use VBA Message Box in Excel?<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[747],"tags":[748],"class_list":["post-6711","post","type-post","status-publish","format-standard","hentry","category-vba-message-box-in-excel","tag-vba-message-box-in-excel"],"_links":{"self":[{"href":"https:\/\/www.bizinfograph.com\/resource\/wp-json\/wp\/v2\/posts\/6711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bizinfograph.com\/resource\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bizinfograph.com\/resource\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bizinfograph.com\/resource\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bizinfograph.com\/resource\/wp-json\/wp\/v2\/comments?post=6711"}],"version-history":[{"count":6,"href":"https:\/\/www.bizinfograph.com\/resource\/wp-json\/wp\/v2\/posts\/6711\/revisions"}],"predecessor-version":[{"id":9181,"href":"https:\/\/www.bizinfograph.com\/resource\/wp-json\/wp\/v2\/posts\/6711\/revisions\/9181"}],"wp:attachment":[{"href":"https:\/\/www.bizinfograph.com\/resource\/wp-json\/wp\/v2\/media?parent=6711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bizinfograph.com\/resource\/wp-json\/wp\/v2\/categories?post=6711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bizinfograph.com\/resource\/wp-json\/wp\/v2\/tags?post=6711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}