Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
carl
 
Posts: n/a
Default 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   Report Post  
Frank Kabel
 
Posts: n/a
Default

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   Report Post  
Don Guillett
 
Posts: n/a
Default

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   Report Post  
carl
 
Posts: n/a
Default

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   Report Post  
Ron Rosenfeld
 
Posts: n/a
Default

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   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!
Reply
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
Why is the order of my data table opposite from graph? mozermodo Charts and Charting in Excel 6 April 25th 23 03:43 AM
Extract hyperlink string from excel cell Ryan Sapien Links and Linking in Excel 1 January 20th 05 12:24 AM
I want a purchase order that includes page number (if to be order. Angela New Users to Excel 1 December 3rd 04 04:39 PM
Daily Macro to Download Data, Order and paste in order Iarla Excel Worksheet Functions 1 November 17th 04 01:59 PM
How do you extract numbers from a string of chacters in a cell (E. blackbeemer Excel Worksheet Functions 6 November 12th 04 09:00 AM


All times are GMT +1. The time now is 05:53 PM.

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

About Us

"It's about Microsoft Excel"