{"id":491,"date":"2019-02-14T23:44:22","date_gmt":"2019-02-14T23:44:22","guid":{"rendered":"http:\/\/www.vbastring.com\/blog\/?p=491"},"modified":"2019-02-17T20:31:56","modified_gmt":"2019-02-17T20:31:56","slug":"how-to-check-cell-value-in-vba-and-display-message-box","status":"publish","type":"post","link":"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/","title":{"rendered":"How To Check Cell Value In VBA And Display Message Box"},"content":{"rendered":"<p>This post is to help answer a question from the youtube video at https:\/\/www.youtube.com\/watch?v=kamx7NnsCZI&#038;t=2s<\/p>\n<blockquote><p>hi, i need help with the msgbox. I would like a msgbox to pop up if a particular value is smaller than a condition value eg. is 39 < 40, a msgbox should pop up to indicate that the number is smaller. How can I go about doing this?\ufeff<\/p><\/blockquote>\n<p>For starters make sure your workbook is a &#8220;.xlsm&#8221;<\/p>\n<p>Here is the data:<br \/>\n<a href=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Check_Cell_Value_In_VBA_And_Display_Message_Box-b.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Check_Cell_Value_In_VBA_And_Display_Message_Box-b.png?resize=725%2C381\" alt=\"\" width=\"725\" height=\"381\" class=\"alignleft size-full wp-image-493\" \/><\/a><\/p>\n<p>We are going to loop through the cells in A2 to A14, and check if they are less than the value in D2, and if the value is less, we will display a message box.<\/p>\n<p>Here is the code:<\/p>\n<pre class=\"lang:vb decode:true \" >Sub Button1_Click()\r\n    Dim dblValue As Double\r\n    Dim rngValues As Range\r\n    \r\n    'this will be my check cell value\r\n    dblValue = Range(\"D2\")\r\n    \r\n    'Set the range to loop through:\r\n    Set rngValues = Sheet1.Range(\"A2:A14\")\r\n    \r\n    \r\n    'loop through all the cells in the range:\r\n    For Each cell In rngValues\r\n        If cell.Value &lt; dblValue Then\r\n            MsgBox \"The value in \" &amp; cell.Address &amp; \" is smaller than the checked value\"\r\n        End If\r\n    Next\r\n    \r\nEnd Sub\r\n<\/pre>\n<p>Now when the button &#8220;Button 1&#8221; is clicked and cells will be evaluated and display a message box if the condition is met.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Check_Cell_Value_In_VBA_And_Display_Message_Box2.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Check_Cell_Value_In_VBA_And_Display_Message_Box2.png?resize=1210%2C556\" alt=\"\" width=\"1210\" height=\"556\" class=\"alignleft size-full wp-image-494\" \/><\/a><\/p>\n<p>Let me know if you have any questions.<\/p>\n<p>****************************************************<\/p>\n<table border=\"1\" width=\"100%\">\n<tr>\n<td align=\"middle\">\n<div class=\"AW-Form-1094354588\"><\/div>\n<p><script type=\"text\/javascript\">(function(d, s, id) {\n    var js, fjs = d.getElementsByTagName(s)[0];\n    if (d.getElementById(id)) return;\n    js = d.createElement(s); js.id = id;\n    js.src = \"\/\/forms.aweber.com\/form\/88\/1094354588.js\";\n    fjs.parentNode.insertBefore(js, fjs);\n    }(document, \"script\", \"aweber-wjs-kkrwj13ov\"));\n<\/script>\n<\/td>\n<\/tr>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>This post is to help answer a question from the youtube video at https:\/\/www.youtube.com\/watch?v=kamx7NnsCZI&#038;t=2s hi, i need help with the msgbox. I would like a msgbox to pop up if a particular value is smaller than a condition value eg. is 39 < 40, a msgbox should pop up to indicate that the number is [&hellip;]\n<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","om_disable_all_campaigns":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-491","post","type-post","status-publish","format-standard","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How To Check Cell Value In VBA And Display Message Box - My Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Check Cell Value In VBA And Display Message Box - My Blog\" \/>\n<meta property=\"og:description\" content=\"This post is to help answer a question from the youtube video at https:\/\/www.youtube.com\/watch?v=kamx7NnsCZI&#038;t=2s hi, i need help with the msgbox. I would like a msgbox to pop up if a particular value is smaller than a condition value eg. is 39 &lt; 40, a msgbox should pop up to indicate that the number is [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/\" \/>\n<meta property=\"og:site_name\" content=\"My Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-14T23:44:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-17T20:31:56+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Check_Cell_Value_In_VBA_And_Display_Message_Box-b.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/14\\\/how-to-check-cell-value-in-vba-and-display-message-box\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/14\\\/how-to-check-cell-value-in-vba-and-display-message-box\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\"},\"headline\":\"How To Check Cell Value In VBA And Display Message Box\",\"datePublished\":\"2019-02-14T23:44:22+00:00\",\"dateModified\":\"2019-02-17T20:31:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/14\\\/how-to-check-cell-value-in-vba-and-display-message-box\\\/\"},\"wordCount\":162,\"image\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/14\\\/how-to-check-cell-value-in-vba-and-display-message-box\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/How_To_Check_Cell_Value_In_VBA_And_Display_Message_Box-b.png\",\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/14\\\/how-to-check-cell-value-in-vba-and-display-message-box\\\/\",\"url\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/14\\\/how-to-check-cell-value-in-vba-and-display-message-box\\\/\",\"name\":\"How To Check Cell Value In VBA And Display Message Box - My Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/14\\\/how-to-check-cell-value-in-vba-and-display-message-box\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/14\\\/how-to-check-cell-value-in-vba-and-display-message-box\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/How_To_Check_Cell_Value_In_VBA_And_Display_Message_Box-b.png\",\"datePublished\":\"2019-02-14T23:44:22+00:00\",\"dateModified\":\"2019-02-17T20:31:56+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/14\\\/how-to-check-cell-value-in-vba-and-display-message-box\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/14\\\/how-to-check-cell-value-in-vba-and-display-message-box\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/14\\\/how-to-check-cell-value-in-vba-and-display-message-box\\\/#primaryimage\",\"url\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/How_To_Check_Cell_Value_In_VBA_And_Display_Message_Box-b.png\",\"contentUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/How_To_Check_Cell_Value_In_VBA_And_Display_Message_Box-b.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/14\\\/how-to-check-cell-value-in-vba-and-display-message-box\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Check Cell Value In VBA And Display Message Box\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/\",\"name\":\"My Blog\",\"description\":\"My WordPress Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\\\/\\\/vbastring.com\\\/blog\"],\"url\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Check Cell Value In VBA And Display Message Box - My Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/","og_locale":"en_US","og_type":"article","og_title":"How To Check Cell Value In VBA And Display Message Box - My Blog","og_description":"This post is to help answer a question from the youtube video at https:\/\/www.youtube.com\/watch?v=kamx7NnsCZI&#038;t=2s hi, i need help with the msgbox. I would like a msgbox to pop up if a particular value is smaller than a condition value eg. is 39 < 40, a msgbox should pop up to indicate that the number is [&hellip;]","og_url":"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/","og_site_name":"My Blog","article_published_time":"2019-02-14T23:44:22+00:00","article_modified_time":"2019-02-17T20:31:56+00:00","og_image":[{"url":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Check_Cell_Value_In_VBA_And_Display_Message_Box-b.png","type":"","width":"","height":""}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/#article","isPartOf":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/"},"author":{"name":"admin","@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5"},"headline":"How To Check Cell Value In VBA And Display Message Box","datePublished":"2019-02-14T23:44:22+00:00","dateModified":"2019-02-17T20:31:56+00:00","mainEntityOfPage":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/"},"wordCount":162,"image":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/#primaryimage"},"thumbnailUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Check_Cell_Value_In_VBA_And_Display_Message_Box-b.png","inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/","url":"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/","name":"How To Check Cell Value In VBA And Display Message Box - My Blog","isPartOf":{"@id":"https:\/\/vbastring.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/#primaryimage"},"image":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/#primaryimage"},"thumbnailUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Check_Cell_Value_In_VBA_And_Display_Message_Box-b.png","datePublished":"2019-02-14T23:44:22+00:00","dateModified":"2019-02-17T20:31:56+00:00","author":{"@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5"},"breadcrumb":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/#primaryimage","url":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Check_Cell_Value_In_VBA_And_Display_Message_Box-b.png","contentUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How_To_Check_Cell_Value_In_VBA_And_Display_Message_Box-b.png"},{"@type":"BreadcrumbList","@id":"https:\/\/vbastring.com\/blog\/2019\/02\/14\/how-to-check-cell-value-in-vba-and-display-message-box\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vbastring.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How To Check Cell Value In VBA And Display Message Box"}]},{"@type":"WebSite","@id":"https:\/\/vbastring.com\/blog\/#website","url":"https:\/\/vbastring.com\/blog\/","name":"My Blog","description":"My WordPress Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vbastring.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/vbastring.com\/blog"],"url":"https:\/\/vbastring.com\/blog\/author\/admin\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/comments?post=491"}],"version-history":[{"count":5,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/491\/revisions"}],"predecessor-version":[{"id":514,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/491\/revisions\/514"}],"wp:attachment":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/media?parent=491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/categories?post=491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/tags?post=491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}