How do i count the number of occurrence for a string in a cell?

Viewed 4017

I am trying to count the number of occurrence for this phrase "SMM:" in each row in column AJ starting from row 2 and then assign the assign the value for each row to column BL starting from row 2.

Sub calculateamlp()


Dim charactercount As Integer
Dim rangeAG As Range
Dim cellCheck As Range
Dim f As Integer
f = 2
 Worksheets("pptsr").Activate

Set rangeAG2 = Range("BL2", Range("BL2").End(xlDown))
Set rangeAG = Range("Aj2", Range("Aj2").End(xlDown))
For Each cellCheck In rangeAG

        charactercount = Len(cellCheck) - Len(WorksheetFunction.Substitute(cellCheck, ":", ""))


        Worksheets("pptsr").Range("BL2" & f).Value = charactercount

   f = f + 1
Next cellCheck

End Sub
2 Answers
Related