Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
ac512
 
Posts: n/a
Default Reversing cell values

how do I reverse the values of a cell (eg. 1234 becomes 4321)???
  #2   Report Post  
Andy Brown
 
Posts: n/a
Default

"ac512" wrote in message
...
how do I reverse the values of a cell (eg. 1234 becomes 4321)???


Try this UDF (from John Walkenbach's site) in a plain VBA module:

Function Reverse(InString) As String
'UDF to reverse string - John W
Dim i As Integer
Dim StringLength As Integer
Reverse = ""
StringLength = Len(InString)
For i = StringLength To 1 Step -1
Reverse = Reverse & Mid(InString, i, 1)
Next i
End Function

HTH,
Andy


  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default

And if you're using xl2k or higher, you can use a builtin VBA function:

Option Explicit
Function Reverse2(InString) As String
Reverse2 = StrReverse(InString)
End Function



Andy Brown wrote:

"ac512" wrote in message
...
how do I reverse the values of a cell (eg. 1234 becomes 4321)???


Try this UDF (from John Walkenbach's site) in a plain VBA module:

Function Reverse(InString) As String
'UDF to reverse string - John W
Dim i As Integer
Dim StringLength As Integer
Reverse = ""
StringLength = Len(InString)
For i = StringLength To 1 Step -1
Reverse = Reverse & Mid(InString, i, 1)
Next i
End Function

HTH,
Andy


--

Dave Peterson
  #4   Report Post  
ac512
 
Posts: n/a
Default

Thank you both very much for your assistance!
Much appreciated

"ac512" wrote:

how do I reverse the values of a cell (eg. 1234 becomes 4321)???

  #5   Report Post  
ac512
 
Posts: n/a
Default

this works perfectly, except for the fact that if a number ends in one or
more zeros, the zeros are dropped off

"Andy Brown" wrote:

"ac512" wrote in message
...
how do I reverse the values of a cell (eg. 1234 becomes 4321)???


Try this UDF (from John Walkenbach's site) in a plain VBA module:

Function Reverse(InString) As String
'UDF to reverse string - John W
Dim i As Integer
Dim StringLength As Integer
Reverse = ""
StringLength = Len(InString)
For i = StringLength To 1 Step -1
Reverse = Reverse & Mid(InString, i, 1)
Next i
End Function

HTH,
Andy





  #6   Report Post  
Dave Peterson
 
Posts: n/a
Default

That's odd. Both functions kept the leading zeros for me. (xl2003)

That's when I called it from a worksheet cell:
=reverse(a1)
or
=reverse2(a1)

But if I called it from a sub and populated another cell, I lost the leading
0's.

Sub testme()
Range("B1").Value = Reverse(Range("a1"))
End Sub

But you could do this:
Sub testme2()
Range("B1").Value = "'" & Reverse(Range("a1"))
End Sub

or even:

Sub testme3()
With Range("B1")
.NumberFormat = "@"
.Value = Reverse(Range("a1"))
End With
End Sub



ac512 wrote:

this works perfectly, except for the fact that if a number ends in one or
more zeros, the zeros are dropped off

"Andy Brown" wrote:

"ac512" wrote in message
...
how do I reverse the values of a cell (eg. 1234 becomes 4321)???


Try this UDF (from John Walkenbach's site) in a plain VBA module:

Function Reverse(InString) As String
'UDF to reverse string - John W
Dim i As Integer
Dim StringLength As Integer
Reverse = ""
StringLength = Len(InString)
For i = StringLength To 1 Step -1
Reverse = Reverse & Mid(InString, i, 1)
Next i
End Function

HTH,
Andy




--

Dave Peterson
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
up to 7 functions? ALex Excel Worksheet Functions 10 April 12th 05 06:42 PM
Split cell values based on content mel Excel Worksheet Functions 4 March 30th 05 04:03 PM
how can I select two different values for a cell? Parastoo Parto Excel Worksheet Functions 1 March 9th 05 10:47 AM
limit choice in cell to one of two values; Excel Discussion (Misc queries) 3 February 18th 05 09:04 PM
Stumped! Collecting values into one cell. AthleteTO Excel Worksheet Functions 5 November 2nd 04 04:24 PM


All times are GMT +1. The time now is 11:43 AM.

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"