reverse the word on excel

K

kman

Hi,
Iwant to know if there is a way to reverse the words from left to righ
insteed from right to left for example: "dog" will reverse to "god"

Thank
 
S

scottymelloty

If you put dog in A1

Then copy and paste this into B
=CONCATENATE(MID(A1,3,1),MID(A1,2,1),MID(A1,1,1))

This will reverse a 3 letter word and it will turn dog into god, alth
this formula would have to be changed for each length of word but i
sure someone can figure a better way but its a start for yo
 
J

Jim May

Or UDF:
Function ReverseString(rng As Range) As String
Dim i As Integer
For i = Len(rng.Value) To 1 Step -1
ReverseString = ReverseString & Mid(rng.Value, i, 1)
Next
End Function

then =ReverseString(A1) in B1 'displays taC
where A1 = Cat

HTH
 
J

Jim May

Or If you use Excel 2002 or later, you could use this UDF:

Function Reverse(str As String) As String
Reverse = StrReverse(str)
End Function



Jim May said:
Or UDF:
Function ReverseString(rng As Range) As String
Dim i As Integer
For i = Len(rng.Value) To 1 Step -1
ReverseString = ReverseString & Mid(rng.Value, i, 1)
Next
End Function

then =ReverseString(A1) in B1 'displays taC
where A1 = Cat

HTH
 
B

Bob Phillips

Probably best to use a UDF for this. Here is an example

Function ReverseText(inpText)
Dim i As Long
Dim sTemp
Dim sTemp1 As String

If TypeName(inpText) = "Range" Then
If inpText.Count > 1 Then
ReverseText = CVErr(xlErrRef)
Exit Function
End If
sTemp = inpText.Value
Else
sTemp = inpText
End If

If VarType(sTemp) <> vbString Then
ReverseText = CVErr(xlErrValue)
Else
For i = Len(sTemp) To 1 Step -1
sTemp1 = sTemp1 & Mid(sTemp, i, 1)
Next i
ReverseText = sTemp1
End If
End Function
 
Top