| Count the number of times stringA occurs in StringB. Inputs:2 String Inputs, one to search in, the other to search for. Returns:Long value of number of times your string was found. Assumes:Place this code in a new module and call it like so: MsgBox CountStringInString("XoXoXoXx", "X") Returns 4. Option Explicit Public Function CountStringInString(str2Search As String, str2Count As String) As Long Private lngPlace As Long, lngCount As Long, lngFind As Long, l As Long lngFind = -1: lngPlace = 1 Do Until lngPlace = Len(str2Search) Or lngFind = 0 lngCount = lngCount + 1 lngFind = InStr(lngPlace, str2Search, str2Count, vbBinaryCompare) 'Becase Case Matters. lngPlace = lngFind + 1 Loop CountStringInString = lngCount - 1 End Function |
Count String In String |
India web developer web development India | India web development company India ecommerce web developer