LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Function to return Character Position of Xth character within a st

Thanks Ton - that does work as well.

As I had a bit of time to play with this one I have actually managed to
solve it myself by re-engineering the MyExtract function from

http://www.meadinkent.co.uk/xlextracttext.htm

Here is my code - I have also managed to get it to look from the front or
the back....

Function CountMyChar(strCSV As String, ItemNo As Integer, FrontOrBack As
String, _
MySeparator As String) As String

Dim i As Long
Dim OneItem As String
Dim n As Integer
Dim Var_CharCount As Integer
Dim Var_NumCharCount As Integer 'n'th item to find position of

Var_CharCount = 0 'current count of Item is 0

If UCase(FrontOrBack) = "F" Then
MySt = 1
MyFin = Len(strCSV)
MyStep = 1
Else
MySt = Len(strCSV)
MyFin = 1
MyStep = -1
End If

For n = MySt To MyFin Step MyStep
char = Mid(strCSV, n, 1)

If char = MySeparator Then
Var_NumCharCount = Var_NumCharCount + 1
End If

If Var_NumCharCount = ItemNo Then
Exit For
End If

Next n

CountMyChar = n

End Function


"TT" wrote in message
...
Hi,

If I understand you correctly you want to find the position of for
example the 4th comma in a string?
This function might do that:

Function iGetPosition(sInput As String, sSeparator As String, iNth As
Integer) As Integer
Dim iPos As Integer, iCnt As Integer

iPos = 0
For iCnt = 1 To iNth
iPos = InStr(iPos + 1, sInput, sSeparator)
If iPos = 0 Then
' bail out when the separator is not found
Exit For
End If
Next iCnt

iGetPosition = iPos
End Function

Sub Effe()
' we should see 18 as a result; let's cross fingers...
Debug.Print iGetPosition("aap,noot,mies,wim,zus,jet", ",", 4)
End Sub


With kind regards,
Ton Teuns

*** Sent via Developersdex http://www.developersdex.com ***




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
return a character at a certain position in a string of text Miranda Excel Worksheet Functions 3 May 8th 23 11:46 AM
Return position of 2nd, 3rd, ect occurrence of a character in a st jheby Excel Discussion (Misc queries) 5 April 21st 23 09:06 AM
Excel-Match 1st text character in a string to a known character? bushlite Excel Worksheet Functions 2 January 15th 07 06:36 PM
function for finding position of numeric character in a string Paul Excel Programming 5 February 6th 05 12:19 AM
How find character position # in string from right end? Or how get range row num Ian Elliott[_3_] Excel Programming 1 December 17th 03 03:56 PM


All times are GMT +1. The time now is 02:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"