Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default reverse text

I try to write a macro that reverse the following text :


"abc 12/34"

to

"cba 12/34"

i.e., it reverses only the text, not the numbers.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default reverse text

'-------------------------------------
Sub test()
Dim MyString As String
Dim NewString As String
MyString = "abc 12/34"
NewString = Mid(MyString, 3, 1) & Mid(MyString, 2, 1) _
& Mid(MyString, 1, 1) & Right(MyString, 6)
MsgBox (MyString & vbCr & NewString)
End Sub
'------------------------------------------



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default reverse text

I guess I did not explain my self right.

The text is not a constant, but random variable, for example:

a street address.


BrianB, wrote in message ...
'-------------------------------------
Sub test()
Dim MyString As String
Dim NewString As String
MyString = "abc 12/34"
NewString = Mid(MyString, 3, 1) & Mid(MyString, 2, 1) _
& Mid(MyString, 1, 1) & Right(MyString, 6)
MsgBox (MyString & vbCr & NewString)
End Sub
'------------------------------------------



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default reverse text

One way is to look for that space and then reverse it based on where you found
it.

Option Explicit
Sub testme()
Dim myCell As Range
Dim SpacePosition As Long

For Each myCell In Selection.Cells
SpacePosition = InStr(1, myCell.Value, " ")
If SpacePosition 0 Then
myCell.Value = Mid(myCell.Value, SpacePosition + 1) _
& " " & Left(myCell.Value, SpacePosition - 1)
End If
Next myCell

End Sub

Select a range and try it out.

don't select cells that are formulas--you'll lose them if you run this.


levyta wrote:

I guess I did not explain my self right.

The text is not a constant, but random variable, for example:

a street address.

BrianB, wrote in message ...
'-------------------------------------
Sub test()
Dim MyString As String
Dim NewString As String
MyString = "abc 12/34"
NewString = Mid(MyString, 3, 1) & Mid(MyString, 2, 1) _
& Mid(MyString, 1, 1) & Right(MyString, 6)
MsgBox (MyString & vbCr & NewString)
End Sub
'------------------------------------------



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default reverse text

the macro does not do what I hoped for.

suppose we have:

abc 12/34 efg

the macro gives:

12/34 efg abc


and not:

cba 12/34 gfe


hope some one can help me.



Dave Peterson wrote in message ...
One way is to look for that space and then reverse it based on where you found
it.

Option Explicit
Sub testme()
Dim myCell As Range
Dim SpacePosition As Long

For Each myCell In Selection.Cells
SpacePosition = InStr(1, myCell.Value, " ")
If SpacePosition 0 Then
myCell.Value = Mid(myCell.Value, SpacePosition + 1) _
& " " & Left(myCell.Value, SpacePosition - 1)
End If
Next myCell

End Sub

Select a range and try it out.

don't select cells that are formulas--you'll lose them if you run this.


levyta wrote:

I guess I did not explain my self right.

The text is not a constant, but random variable, for example:

a street address.

BrianB, wrote in message ...
'-------------------------------------
Sub test()
Dim MyString As String
Dim NewString As String
MyString = "abc 12/34"
NewString = Mid(MyString, 3, 1) & Mid(MyString, 2, 1) _
& Mid(MyString, 1, 1) & Right(MyString, 6)
MsgBox (MyString & vbCr & NewString)
End Sub
'------------------------------------------



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

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
Reverse / Mirror Image of Text griowa87 Excel Discussion (Misc queries) 1 April 13th 10 06:15 PM
How to Reverse Text in Excel without VBA Sheikh Saadi Excel Worksheet Functions 7 September 3rd 09 12:57 AM
Reverse Text to Columns MarvInBoise Excel Discussion (Misc queries) 3 September 27th 06 04:50 PM
Reverse Text by Word?? The Moose Excel Discussion (Misc queries) 3 September 8th 06 05:41 PM
reverse text tom mcdonald Excel Worksheet Functions 5 October 2nd 05 01:04 AM


All times are GMT +1. The time now is 02:53 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"