{"id":11288,"date":"2019-09-20T13:17:17","date_gmt":"2019-09-20T11:17:17","guid":{"rendered":"https:\/\/www.myexcelonline.com\/?p=11288"},"modified":"2024-02-06T16:16:05","modified_gmt":"2024-02-06T15:16:05","slug":"highlight-and-count-a-specified-value-using-macros-in-excel","status":"publish","type":"post","link":"https:\/\/www.myexcelonline.com\/meo-staging\/blog\/highlight-and-count-a-specified-value-using-macros-in-excel\/","title":{"rendered":"Highlight and Count a Specified Value Using Macros In Excel"},"content":{"rendered":"<p>Let us try something fun using Excel <a class=\"wpil_keyword_link\" href=\"https:\/\/www.myexcelonline.com\/meo-staging\/blog\/101-excel-macros-examples\/\" target=\"_blank\" rel=\"noopener\" title=\"Macros\" data-wpil-keyword-link=\"linked\">Macros<\/a>. We want to<strong> highlight a specified value from the user, then show the count as well<\/strong>! You will learn how to show a message back as well to your Excel user.<\/p>\n<p>Make sure your Excel has the Developer Tab enabled following\u00a0<a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/blog\/how-to-create-your-first-macro-button-in-excel-beginners-tutorial\/\" target=\"_blank\" rel=\"noopener noreferrer\">this tutorial<\/a>.<\/p>\n<p>I explain how you can do this below step by step!<\/p>\n<p><em><strong>What does it do?<\/strong><\/em><\/p>\n<p>Highlight and show the count of a specified value<\/p>\n<p><em><strong>Copy Source Code:<\/strong><\/em><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n\r\nSub HighlightAndCountSpecifiedValue()\r\n\r\nDim cell As Range\r\nDim counter As Integer\r\nDim specificValue As Variant\r\n\r\n'Get the specific value from the user\r\nspecificValue = InputBox(&amp;quot;Enter Value To Highlight&amp;quot;, &amp;quot;Enter Value&amp;quot;)\r\n\r\nFor Each cell In ActiveSheet.UsedRange\r\n\r\n'If it matches the specified value, then change the style to be Note\r\nIf cell = specificValue Then\r\ncell.Style = &amp;quot;Note&amp;quot;\r\ncounter = counter + 1\r\nEnd If\r\nNext cell\r\n\r\n'Show the total count to the user\r\nMsgBox &amp;quot;There are a total of &amp;quot; &amp;amp; counter &amp;amp;&amp;quot; &amp;quot;&amp;amp; specificValue &amp;amp; &amp;quot; in this worksheet.&amp;quot;\r\n\r\nEnd Sub\r\n\r\n<\/pre>\n<p><em><strong>Final Result:\u00a0<\/strong><\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"Highlight and Count a Specified Value Using Macros In Excel\"  class=\"aligncenter size-full wp-image-11750\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-05.jpg\" alt=\"Highlight and Count a Specified Value Using Macros In Excel\" width=\"544\" height=\"211\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-05.jpg 544w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-05-300x116.jpg 300w\" sizes=\"(max-width: 544px) 100vw, 544px\" \/><\/p>\n<p><em><strong>Exercise Workbook:<\/strong><\/em><\/p>\n<div class=\"after-post-box\">\n<p><iframe src=\"https:\/\/www.youtube.com\/embed\/I6MtNCTlC8Y?rel=0 \" width=\"800\" height=\"400\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><span data-mce-type=\"bookmark\" style=\"display: inline-block; width: 0px; overflow: hidden; line-height: 0;\" class=\"mce_SELRES_start\">\ufeff<\/span><\/iframe><a href=\"https:\/\/www.youtube.com\/c\/MyExcelOnlinecomtutorials?sub_confirmation=1\" target=\"_blank\" rel=\"noopener noreferrer nofollow\"><img loading=\"lazy\" decoding=\"async\" class=\"alignmiddle wp-image-111468 size-full\" style=\"vertical-align: middle;\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/04\/1.yt_.png\" alt=\"\" title=\"\"><\/a><\/p>\n<p class=\"line-two\"><a class=\"IRPP_minimalist icon-download button small\" href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value.xlsm\" target=\"_blank\" rel=\"noopener noreferrer\" data-leadbox=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value.xlsm\" data-leadbox-id=\"147284833f72a2:12f08263ab46dc\"><span class=\"ctaText px-3 text-capitalize\">Download excel workbook<i class=\"fa fa-download\"><\/i><\/span><span class=\"postTitle px-3\">Highlight-and-Count-a-Specified-Value.xlsm<\/span><\/a><\/p>\n<p class=\"line-two\">\n<\/div>\n<hr \/>\n<p>This is our initial set of data:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"Highlight and Count a Specified Value Using Macros In Excel\"  class=\"aligncenter size-full wp-image-11746\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-01.jpg\" alt=\"Highlight and Count a Specified Value Using Macros In Excel\" width=\"198\" height=\"194\" \/><\/p>\n<p><span style=\"color: #ff0000;\"><strong>STEP 1:<\/strong><\/span>\u00a0Go to\u00a0<em><strong>Developer &gt; Code &gt; Visual Basic<\/strong><\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-10906 aligncenter\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/01\/How-to-Insert-Multiple-Columns-01.jpg\" alt=\"\" width=\"816\" height=\"139\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/01\/How-to-Insert-Multiple-Columns-01.jpg 816w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/01\/How-to-Insert-Multiple-Columns-01-300x51.jpg 300w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/01\/How-to-Insert-Multiple-Columns-01-768x131.jpg 768w\" sizes=\"(max-width: 816px) 100vw, 816px\" title=\"\"><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\"><strong>STEP 2:<\/strong><\/span>\u00a0Paste in your code and\u00a0<strong>Select Save<\/strong>. Close the window afterwards.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"Highlight and Count a Specified Value Using Macros In Excel\"  class=\"aligncenter size-full wp-image-11747\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-02.jpg\" alt=\"Highlight and Count a Specified Value Using Macros In Excel\" width=\"1029\" height=\"491\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-02.jpg 1029w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-02-300x143.jpg 300w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-02-1024x489.jpg 1024w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-02-768x366.jpg 768w\" sizes=\"(max-width: 1029px) 100vw, 1029px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\"><strong>STEP 3:\u00a0<\/strong><\/span>Let us test it out!<\/p>\n<p>Open the sheet containing the data. Go to\u00a0<em><strong>Developer &gt; Code &gt; Macros<\/strong><\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11245\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/03\/Unmerge-Cells-02.jpg\" alt=\"\" width=\"854\" height=\"142\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/03\/Unmerge-Cells-02.jpg 854w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/03\/Unmerge-Cells-02-300x50.jpg 300w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/03\/Unmerge-Cells-02-768x128.jpg 768w\" sizes=\"(max-width: 854px) 100vw, 854px\" title=\"\"><\/p>\n<p>&nbsp;<\/p>\n<p>Make sure your <a class=\"wpil_keyword_link\" href=\"https:\/\/www.myexcelonline.com\/meo-staging\/blog\/101-excel-macros-examples\/\" target=\"_blank\" rel=\"noopener\" title=\"macro\" data-wpil-keyword-link=\"linked\">macro<\/a> is selected. Click <strong>Run<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"Highlight and Count a Specified Value Using Macros In Excel\"  class=\"aligncenter size-full wp-image-11748\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-03.jpg\" alt=\"Highlight and Count a Specified Value Using Macros In Excel\" width=\"661\" height=\"383\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-03.jpg 661w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-03-300x174.jpg 300w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><\/p>\n<p>Type in the value to highlight and count. Let us type in\u00a0<strong>Ian Wright<\/strong>. Click\u00a0<strong>OK.<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"Highlight and Count a Specified Value Using Macros In Excel\"  class=\"aligncenter size-full wp-image-11749\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-04.jpg\" alt=\"Highlight and Count a Specified Value Using Macros In Excel\" width=\"359\" height=\"152\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-04.jpg 359w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-04-300x127.jpg 300w\" sizes=\"(max-width: 359px) 100vw, 359px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>With just one click, <strong>all of the Ian Wright values are now highlighted and you see the count as well!<\/strong><\/p>\n<p><span style=\"color: #0000ff;\"><strong>\u00a0<img loading=\"lazy\" decoding=\"async\" title=\"Highlight and Count a Specified Value Using Macros In Excel\"  class=\"aligncenter size-full wp-image-11750\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-05.jpg\" alt=\"Highlight and Count a Specified Value Using Macros In Excel\" width=\"544\" height=\"211\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-05.jpg 544w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/05\/Highlight-and-Count-a-Specified-Value-05-300x116.jpg 300w\" sizes=\"(max-width: 544px) 100vw, 544px\" \/><\/strong><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #0000ff;\"><strong>How to Highlight and Count a Specified Value Using Macros In Excel<\/strong><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/100-66.html\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-13266\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/10\/101-Macros-Book.png\" alt=\"101 Macros Book\" width=\"1200\" height=\"628\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/10\/101-Macros-Book.png 1200w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/10\/101-Macros-Book-300x157.png 300w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/10\/101-Macros-Book-1024x536.png 1024w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2019\/10\/101-Macros-Book-768x402.png 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let us try something fun using Excel Macros. We want to highlight a specified value from the user, then show the count as well! You will learn how to show a message back as well to your Excel user. Make sure your Excel has the Developer Tab enabled following\u00a0this tutorial. I explain how you can [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":18094,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"cos_headline_score":0,"cos_seo_score":0,"cos_headline_text":"","cos_headline_has_been_analyzed":false,"cos_last_analyzed_headline":[],"om_disable_all_campaigns":false},"categories":[56,642],"tags":[106],"acf":[],"_links":{"self":[{"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/posts\/11288"}],"collection":[{"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/comments?post=11288"}],"version-history":[{"count":0,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/posts\/11288\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/media\/18094"}],"wp:attachment":[{"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/media?parent=11288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/categories?post=11288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/tags?post=11288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}