By using expertatexcel.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

Become an Σxpert at Σxcel.com

 


Replace

Replace is a highly used Built-in VBA function

Immediate Window


s = "abcdef"
s = Replace(s,"abc","def")
? s

defdef





Replace can be used to find the number of occurrences of a string.

Function CountString(s As String, sMatch As String)
sWork = LCase(s)
sWorkMatch = LCase(sMatch)
CountString = (Len(s) - Len(Replace(sWork, sWorkMatch, ""))) / Len(sMatch)

End Function


Immediate Window

? countstring("The best part is the best part","the") ' case issue?