Using VBA for Excel 98, I need to find and retrieve the position of a caractere in a string, e.g:
string: "teste"
find the position of "s", in this case, = 3
thx
Pacheco
Using VBA for Excel 98, I need to find and retrieve the position of a caractere in a string, e.g:
string: "teste"
find the position of "s", in this case, = 3
thx
Pacheco
Welcome to the forum!
You could try
Dim i as integer
Dim Pos As integer
Dim FindChar as string
Dim SearchString As String
SearchString = "teste"
FindChar = "s"
For i = 1 To Len(SearchString)
If Mid(SearchString, i, 1) = FindChar Then
Pos = i
End If
Next i
MsgBox FindChar & " was Found at position " & Pos
Display More
HTH
Instr("teste","s")
will return 3 (a return of 0 means the character is not found)
thx all!
Re: How to find a character in a string
Thank you very much for the code.
Don’t have an account yet? Register yourself now and be a part of our community!