View Single Post
  #6   Report Post  
hrlngrv - ExcelForums.com
 
Posts: n/a
Default

Ron Rosenfeld wrote...
...
Function Rev(str As String, sep As String) As String

...
temp = Split(str, sep)
...
Rev = Join(temp1, sep)
End Function
...

Should avoid Split and Join unless the OP mentions that s/he uses
Excel 2000 or later. You udf won't work in Excel 97 or 95. For that
matter, Split and Join can only handle single character separators.
Adequate for the OP's sample data, but if you're going to write a
udf, it might as well be as general as possible.

For literal, possibly multiple character separator strings,


Function rf(s As String, sep As String) As String
Dim k As Long, n As Long, p As Long, q As Long

n = Len(s)
k = Len(sep)
q = n - k + 1

For p = q To 1 Step -1
If Mid(s, p, k) = sep Or p = 1 Then
If p = 1 Then
rf = rf & Mid(s, p, q + 1)
Else
rf = rf & Mid(s, p + k, q - p) & sep
q = p - k
End If
End If
Next p

End Function
---------
www.coffeecozy.com

Use your Bodum and give up cold coffee for good!