George offered what he did because of the phrase "find the position of the nth character in a string". It doesn't make much sense as is.
Technically - the answer to that question is N.
But you're wanting the position of the nth occurance of a specified character.
Why do you want that character's position?
Here's a non-rigourously tested different take on the task than normal.
Code:
Function fGetCharPos(strText As String, strChar As String, Optional intPos As Integer = 1)
On Error Resume Next
Dim strArr() As String
strArr = Split(strText, strChar)
ReDim Preserve strArr(intPos - 1)
fGetCharPos = Len(Join(strArr)) + (Len(strChar) - 1) * (intPos - 1) + 1
End Function
Fair enough - the function as suggested should be enough for you.
Or you could amend it to return the string to the left, rather than just the position.
e.g.
Code:
Function fGetChars(strText As String, strChar As String, Optional intPos As Integer = 1)
On Error Resume Next
Dim strArr() As String
strArr = Split(strText, strChar)
ReDim Preserve strArr(intPos - 1)
fGetChars = Join(strArr, strChar) & strChar
End Function
what about two nested inStr()? find the first postion using inStr (use 1 as the start parameter), then if it finds it alter your start parameter to be the result of the first inStr.
Code:
If instr(1,"a","abcabc") > 0 then
intposition = instr(instr(1,"a","abcabc")+ 1, "a","abcabc")
end if
Yeah. Using InStr would a more traditional method - though, obviously, you'd have to write a function to call it iteratively on the string provided for the required number of occurances (hard coding it to two levels - or more - would be much too limited as a solution).
I offered the function solution as presented mainly because Split has become the common trend for more abbreviated code (i.e. it's cooler ;-).