By using vba.booksticle.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes
Something went wrong.
Something went wrong.
Something went wrong.
   dbr2598: 0

948 Steps to 6 Figures by Learning Excel-VBA and Other Skills



Step -1 - 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?





   Table of Contents | Send us your feedback | © 2025 All Rights Reserved | Edit