{"id":4659,"date":"2016-10-25T11:26:53","date_gmt":"2016-10-25T09:26:53","guid":{"rendered":"https:\/\/www.myexcelonline.com\/?p=4659"},"modified":"2023-11-30T21:13:49","modified_gmt":"2023-11-30T20:13:49","slug":"count-text-occurrences-excels-substitute-formula","status":"publish","type":"post","link":"https:\/\/www.myexcelonline.com\/meo-staging\/blog\/count-text-occurrences-excels-substitute-formula\/","title":{"rendered":"Count Text Occurrences with Excel&#8217;s SUBSTITUTE Formula"},"content":{"rendered":"<p><em><strong>What does it do?<\/strong><\/em><\/p>\n<p>It\u00a0replaces specific text in a text string i.e. Substitutes new text for old text in a text string.<\/p>\n<p><em><strong>Formula breakdown:<\/strong><\/em><\/p>\n<p>=SUBSTITUTE(<span style=\"color: #0000ff;\">text<\/span>, <span style=\"color: #ff0000;\">old_text<\/span>, <span style=\"color: #339966;\">new_text<\/span>, <span style=\"color: #800080;\">[instance num]<\/span>)<\/p>\n<p><em><strong>What it means:<\/strong><\/em><\/p>\n<p>=SUBSTITUTE(<span style=\"color: #0000ff;\">This cell<\/span>, <span style=\"color: #ff0000;\">From\u00a0this TEXT\u00a0character<\/span>, <span style=\"color: #339966;\">To this TEXT\u00a0character<\/span>,<span style=\"color: #800080;\"> [In the 1st, 2nd\u2026instance it occurs]<\/span>)<\/p>\n<hr \/>\n<p>I had a scenario where I had to count the number of occurrences of a specific character in a cell.<\/p>\n<p>For example, I had to check the number of asterisks * in a cell. \u00a0Why you ask?<\/p>\n<p>Well it was because the asterisks corresponded to the number of times the employee was away that year. \u00a0Who would&#8217;ve thought of putting asterisks, but there you go!<\/p>\n<p>At first, I had no clue on how to do this and it was very cumbersome to do this manually!<\/p>\n<p>Turns out, the <b>SUBSTITUTE\u00a0<\/b>formula in Excel can be used creatively to extract the count easily!<\/p>\n<p>Here&#8217;s an example:<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-Ex.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\"  class=\"alignnone size-full wp-image-4669\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-Ex.png\" alt=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\" width=\"227\" height=\"50\" \/><\/a><\/p>\n<p>We want to return the count of asterisks here, which is 7. We will use a combination of the\u00a0<strong>LEN\u00a0<\/strong>formula and the\u00a0 <strong>SUBSTITUTE<\/strong> formula.<\/p>\n<p>We will have 3 main steps:<\/p>\n<ul>\n<li><strong>Get the length of the entire string<\/strong> &#8211; in this case, the length of\u00a0&#8220;Bradley Strickland *******&#8221; would be 26.<\/li>\n<li><strong>Get the length of the text without the asterisks<\/strong> &#8211; in this case, the length of &#8220;Bradley Strickland&#8221; would be 19.<\/li>\n<li><strong>Subtract the two lengths<\/strong> &#8211; this will give us 7, which is the number of asterisks.<\/li>\n<\/ul>\n<p>I explain how you can do this and please\u00a0go to the bottom of the page to see the animated gif tutorial:<\/p>\n<div class=\"after-post-box\">\n<p><iframe src=\"https:\/\/www.youtube.com\/embed\/H_qQ70Ttqdo?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\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences.xlsx\" target=\"_blank\" rel=\"noopener noreferrer\" data-leadbox=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences.xlsx\" 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\">SUBSTITUTE-Count-Text-Occurrences.xlsx<\/span><\/a><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\"><strong>STEP 1:<\/strong> <\/span>We need to <strong>use\u00a0the SUBSTITUTE function<\/strong>\u00a0to remove all of the asterisks from the text. We will replace the <strong>asterisk &#8220;*&#8221;<\/strong> with an <strong>empty string &#8220;&#8221;<\/strong>.<\/p>\n<h2 style=\"text-align: center;\"><span style=\"color: #0000ff;\">=SUBSTITUTE(C9, &#8220;*&#8221;, &#8220;&#8221;)<\/span><\/h2>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-01.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\"  class=\"alignnone size-full wp-image-4660\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-01.png\" alt=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\" width=\"463\" height=\"172\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-01.png 463w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-01-300x111.png 300w\" sizes=\"(max-width: 463px) 100vw, 463px\" \/><\/a><\/p>\n<p>You can see now that the asterisks are removed:<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-02.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\"  class=\"alignnone size-full wp-image-4661\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-02.png\" alt=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\" width=\"460\" height=\"179\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-02.png 460w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-02-300x117.png 300w\" sizes=\"(max-width: 460px) 100vw, 460px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\"><strong>STEP 2:<\/strong> <\/span>With this result, we can get the length of the text without asterisks using the <strong>LEN function:<\/strong><\/p>\n<h2 style=\"text-align: center;\"><span style=\"color: #0000ff;\"><span style=\"color: #000000;\">=<\/span>LEN(<\/span><span style=\"color: #000000;\">SUBSTITUTE(C9, &#8220;*&#8221;, &#8220;&#8221;)<\/span><span style=\"color: #0000ff;\">)<\/span><\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\"  class=\"alignnone size-full wp-image-4662\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-03.png\" alt=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\" width=\"556\" height=\"176\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-03.png 556w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-03-300x95.png 300w\" sizes=\"(max-width: 556px) 100vw, 556px\" \/><\/p>\n<p>The length of &#8220;Bradley Strickland&#8221; is 19:<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-04.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\"  class=\"alignnone size-full wp-image-4663\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-04.png\" alt=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\" width=\"461\" height=\"174\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-04.png 461w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-04-300x113.png 300w\" sizes=\"(max-width: 461px) 100vw, 461px\" \/><\/a><\/p>\n<h2><\/h2>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\"><strong>STEP 3:<\/strong> <\/span>Now here is the cool part!<\/p>\n<p>Since we have the length of the text without asterisks, we now get the <strong>length of the complete text with asterisks<\/strong>, then we <strong>subtract them together<\/strong>. This will give us the number of asterisk occurrences in the text!<\/p>\n<h2 style=\"text-align: center;\"><span style=\"color: #0000ff;\"><span style=\"color: #000000;\">=<span style=\"color: #0000ff;\">LEN(C9) &#8211;\u00a0<\/span>LEN(<\/span><\/span><span style=\"color: #000000;\">SUBSTITUTE(C9, &#8220;*&#8221;, &#8220;&#8221;))<\/span><\/h2>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-05.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\"  class=\"alignnone size-full wp-image-4664\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-05.png\" alt=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\" width=\"558\" height=\"176\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-05.png 558w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-05-300x95.png 300w\" sizes=\"(max-width: 558px) 100vw, 558px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>This formula gives us 26 &#8211; 19, wherein 26 is the length of the whole text, while 19 is the length of the text without asterisks.<\/p>\n<p>This will give us 7, which is the exact number of asterisks in the text!<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-06.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\"  class=\"alignnone size-full wp-image-4665\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-06.png\" alt=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\" width=\"458\" height=\"176\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-06.png 458w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-06-300x115.png 300w\" sizes=\"(max-width: 458px) 100vw, 458px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\"><strong>STEP 4:<\/strong> <\/span>Do the same for the rest of the cells by dragging the <b>SUBSTITUTE\u00a0<\/b>formula all the way down using the left mouse button.<\/p>\n<p>Note that all of the counts are automatically calculated:<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-07.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\"  class=\"alignnone size-full wp-image-4666\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-07.png\" alt=\"Count Text Occurrences with Excel&#039;s SUBSTITUTE Formula\" width=\"487\" height=\"200\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-07.png 487w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2016\/09\/SUBSTITUTE-Count-Text-Occurrences-07-300x123.png 300w\" sizes=\"(max-width: 487px) 100vw, 487px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What does it do? It\u00a0replaces specific text in a text string i.e. Substitutes new text for old text in a text string. Formula breakdown: =SUBSTITUTE(text, old_text, new_text, [instance num]) What it means: =SUBSTITUTE(This cell, From\u00a0this TEXT\u00a0character, To this TEXT\u00a0character, [In the 1st, 2nd\u2026instance it occurs]) I had a scenario where I had to count the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":17609,"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":[3,306,14],"tags":[142,174,70],"acf":[],"_links":{"self":[{"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/posts\/4659"}],"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=4659"}],"version-history":[{"count":0,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/posts\/4659\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/media\/17609"}],"wp:attachment":[{"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/media?parent=4659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/categories?post=4659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/tags?post=4659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}