Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Reversing the Order of a String
I have a string like so:
ab;cd;ef;gh is there a way to reverse the order ? eg: gh;ef;cd;ab Thank you in advance |
#2
|
|||
|
|||
Hi
would VBA be feasible for you? "carl" wrote: I have a string like so: ab;cd;ef;gh is there a way to reverse the order ? eg: gh;ef;cd;ab Thank you in advance |
#3
|
|||
|
|||
if always in the same place
=MID(E1,10,2)&MID(E1,6,3)&MID(E1,3,4)&MID(E1,1,2) -- Don Guillett SalesAid Software "carl" wrote in message ... I have a string like so: ab;cd;ef;gh is there a way to reverse the order ? eg: gh;ef;cd;ab Thank you in advance |
#4
|
|||
|
|||
hi frank and thanks. VBA would be fine.
"carl" wrote: I have a string like so: ab;cd;ef;gh is there a way to reverse the order ? eg: gh;ef;cd;ab Thank you in advance |
#5
|
|||
|
|||
On Mon, 6 Dec 2004 05:43:04 -0800, "carl"
wrote: I have a string like so: ab;cd;ef;gh is there a way to reverse the order ? eg: gh;ef;cd;ab Thank you in advance Easy with VBA. <alt-F11 opens the Visual Basic Editor. Ensure your project is highlighted in the project explorer window, then Insert/Module and paste the code below into the window that opens. To use this, enter the function =REV(string, separator) into some cell. String and Separator can either be actual strings, or cell references that contain strings. As written, each variable must be in a single cell. But the UDF can be rewritten if that is not suitable. ======================= Function Rev(str As String, sep As String) As String Dim temp, temp1 Dim i As Integer temp = Split(str, sep) ReDim temp1(UBound(temp)) For i = 0 To UBound(temp) temp1(UBound(temp) - i) = temp(i) Next i Rev = Join(temp1, sep) End Function ======================== --ron |
#6
|
|||
|
|||
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! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Why is the order of my data table opposite from graph? | Charts and Charting in Excel | |||
Extract hyperlink string from excel cell | Links and Linking in Excel | |||
I want a purchase order that includes page number (if to be order. | New Users to Excel | |||
Daily Macro to Download Data, Order and paste in order | Excel Worksheet Functions | |||
How do you extract numbers from a string of chacters in a cell (E. | Excel Worksheet Functions |