+ Reply to Thread
Results 1 to 6 of 6

Reversing cell values

  1. #1
    ac512
    Guest

    Reversing cell values

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

  2. #2
    Andy Brown
    Guest

    Re: Reversing cell values

    "ac512" <[email protected]> wrote in message
    news:[email protected]...
    > 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. #3
    Dave Peterson
    Guest

    Re: Reversing cell values

    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" <[email protected]> wrote in message
    > news:[email protected]...
    > > 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. #4
    ac512
    Guest

    RE: Reversing cell values

    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. #5
    ac512
    Guest

    Re: Reversing cell values

    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" <[email protected]> wrote in message
    > news:[email protected]...
    > > 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. #6
    Dave Peterson
    Guest

    Re: Reversing cell values

    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" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1