title: Counting the matching substrings in range
body: <p>I am working on a workbook in which I need to count how many times the &quot;St/&quot; substring is present in a Range (Column Q). Note: I am interested in all the occurrences, not just the number of cells in which the substring is present. <br>
  Here is the code I am trying to work with (based on the comment of Santhosh Divakar - <a href="https://stackoverflow.com/a/23357807/12536295">https://stackoverflow.com/a/23357807/12536295</a>), but I receive a runtime error (13) when running it. What am I missing / doing wrong?</p>
  <pre><code>Dim lastrow, q as Integer
  lastrow = Range(&quot;A1&quot;).End(xlToRight).End(xlDown).Row
  With Application
  q = .SumProduct((Len(Range(&quot;Q1:Q&quot; &amp; lastrow)) - Len(.Substitute(Range(&quot;Q1:Q&quot; &amp; lastrow), &quot;St/&quot;, &quot;&quot;))) / Len(&quot;St/&quot;))
  End With
  </code></pre>