transpose characters in a cell (ex: ABC12345 changes to 54321CBA)

G

Guest

I looking to take a column of part numbers (mixed with text and numerals) and
transpose the character position from left-to-right - changing it to
right-to-left. An example would be 5YA124 would change to read 421AY5
 
J

JP

Say you are reversing the contents of cell A1, use the code below and
type =ReverseCell(A1,TRUE) in your target cell.


Function ReverseCell(Rcell As Range, Optional IsText As Boolean)
Dim i As Integer
Dim StrNewNum As String
Dim strOld As String
strOld = Trim(Rcell)
For i = 1 To Len(strOld)
StrNewNum = Mid(strOld, i, 1) & StrNewNum
Next i
If IsText = False Then
ReverseCell = CLng(StrNewNum)
Else
ReverseCell = StrNewNum
End If
End Function



HTH,
JP
 
G

Guest

Try this one line UDF:

Function reverse(r As Range) As String
reverse = StrReverse(r.Value)
End Function
 
G

Guest

Thanks!! this works awesome!!!

Gary''s Student said:
Try this one line UDF:

Function reverse(r As Range) As String
reverse = StrReverse(r.Value)
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top