Hello,
I need to get the character instance of the 1st character of a sub-string in a string
I can get the character instance of the entire string but not the 1st character of a sub-string in a string
Ex
ref_value.value = sjdhfss jj sd (ppo nns) GGG
sub-string = sd (ppo nns)
the first instance of substring = s
its instance = 4
Thanks
I need to get the character instance of the 1st character of a sub-string in a string
I can get the character instance of the entire string but not the 1st character of a sub-string in a string
Ex
ref_value.value = sjdhfss jj sd (ppo nns) GGG
sub-string = sd (ppo nns)
the first instance of substring = s
its instance = 4
Thanks
Code:
Function COUNTTEXT(ref_value As Range, ref_string As String) As Long
Dim i As Integer, count As Integer
count = 0
If Len(ref_string) <> 1 Then COUNTTEXT = CVErr(xlErrValue): Exit Function
For i = 1 To Len(ref_value.value)
If Mid(ref_value, i, 1) = ref_string Then count = count + 1
Next
COUNTTEXT = count
End Function
Last edited: