+ Reply to Thread
Results 1 to 13 of 13

Reversing characters of cells

  1. #1
    Forum Contributor
    Join Date
    03-14-2006
    Location
    Pakistan
    Posts
    1,791

    Lightbulb Reversing characters of cells

    how can I reverse the characters of cells.

    (data) (should be)
    12345 54321
    2456 6542
    asdf fdsa
    23 32

    any formula which can do this?

  2. #2
    Alan
    Guest

    Re: Reversing characters of cells

    Can't think of a generic formula but you could use VBA. Position cursor
    over the cell you want to reverse and then run RunReverseData

    Sub RunReverseData()
    Dim CellAddress as string

    CellAddress = Activecell.Address
    Call ReverseData(CellAddress)
    End Sub

    Sub ReverseData(byval CellRef as string)
    Dim i as Integer
    Dim Data as string
    Dim ShouldBe as string

    ShouldBe=""
    Data = Range(CellRef).Value
    for i = 1 to Len(Data)
    ShouldBe=ShouldBe & Mid(Data,Len(Data) - (i-1),1)
    Next i
    Range(CellRef).Value = ShouldBe
    End Sub


  3. #3
    Forum Contributor
    Join Date
    03-14-2006
    Location
    Pakistan
    Posts
    1,791

    Lightbulb

    thanks but I need formula. any guru... on this problem

  4. #4
    Paul Lautman
    Guest

    Re: Reversing characters of cells

    starguy wrote:
    > how can I reverse the characters of cells.
    >
    > (data) (should be)
    > 12345 54321
    > 2456 6542
    > asdf fdsa
    > 23 32
    >
    > any formula which can do this?


    If you know the maximum size of the string in a cell (I shall assume 16)
    then:

    =MID(A1,16,1)&MID(A1,15,1)&MID(A1,14,1)&MID(A1,13,1)&MID(A1,12,1)&MID(A1,11,1)&MID(A1,10,1)&MID(A1,9,1)&MID(A1,8,1)&MID(A1,7,1)&MID(A1,6,1)&MID(A1,5,1)&MID(A1,4,1)&MID(A1,3,1)&MID(A1,2,1)&MID(A1,1,1)



  5. #5
    Paul Lautman
    Guest

    Re: Reversing characters of cells

    starguy wrote:
    > how can I reverse the characters of cells.
    >
    > (data) (should be)
    > 12345 54321
    > 2456 6542
    > asdf fdsa
    > 23 32
    >
    > any formula which can do this?


    alternatively, change the reversedata sub into a function:

    Function ReverseData(cellcont)
    Dim i As Integer
    Dim ShouldBe As String

    ShouldBe = ""
    For i = 1 To Len(cellcont)
    ShouldBe = ShouldBe & Mid(cellcont, Len(cellcont) - (i - 1), 1)
    Next i
    ReverseData = ShouldBe
    End Function



  6. #6
    Forum Contributor
    Join Date
    03-14-2006
    Location
    Pakistan
    Posts
    1,791

    Lightbulb

    thanks its good and easy but too much lengthy to type especially when I have to use it frequently but with different data.

  7. #7
    Paul Lautman
    Guest

    Re: Reversing characters of cells

    starguy wrote:
    > thanks its good and easy but too much lengthy to type especially when
    > I have to use it frequently but with different data.

    Confused???
    What is too lengthy to type?



  8. #8
    Forum Contributor
    Join Date
    03-14-2006
    Location
    Pakistan
    Posts
    1,791

    Lightbulb

    this formula of MID...

    Quote Originally Posted by Paul Lautman
    starguy wrote:
    > thanks its good and easy but too much lengthy to type especially when
    > I have to use it frequently but with different data.

    Confused???
    What is too lengthy to type?

  9. #9
    Forum Contributor
    Join Date
    03-14-2006
    Location
    Pakistan
    Posts
    1,791

    Lightbulb

    this formula of MID...

    Quote Originally Posted by Paul Lautman
    starguy wrote:
    > thanks its good and easy but too much lengthy to type especially when
    > I have to use it frequently but with different data.

    Confused???
    What is too lengthy to type?

  10. #10
    Paul Lautman
    Guest

    Re: Reversing characters of cells

    starguy wrote:
    > this formula of MID...
    >
    > Paul Lautman Wrote:
    >> starguy wrote:
    >>> thanks its good and easy but too much lengthy to type especially
    >>> when I have to use it frequently but with different data.

    >> Confused???
    >> What is too lengthy to type?


    Well, first of all you posted the statment attached to my post about the VBA
    function not the MID one. With the VBA function you only need to type
    something like =ReverseData(A1) in a cell or possibly
    =PERSONAL.XLS!ReverseData(A1) depending on where you stored the UDF.

    Secondly, you say "when I have to use it frequently but with different
    data". The different data makes no difference to what you need to enter, the
    formula remains the same.

    Thirdly, when I have a long formula like that that I need to use often, I
    either make it into a UDF (which I offered you) or if I want to always do it
    in pure Excel functions, I certainly don't retype it every time I want to
    use it!!! I store functions like this in a workbook and copy and paste them
    to other books whenever I need them. If you always retype formulas then more
    fool you!





  11. #11
    Forum Contributor
    Join Date
    03-14-2006
    Location
    Pakistan
    Posts
    1,791

    Lightbulb

    thanks again for explaining. Infact when cell reference is different then it would be tidy to change it in formula on frequent basis.

  12. #12
    Forum Contributor
    Join Date
    03-14-2006
    Location
    Pakistan
    Posts
    1,791

    Lightbulb

    thanks again for explaining. Infact when cell reference is different then it would be tidy to change it in formula on frequent basis.

  13. #13
    Paul Lautman
    Guest

    Re: Reversing characters of cells

    starguy wrote:
    > thanks again for explaining. Infact when cell reference is different
    > then it would be tidy to change it in formula on frequent basis.


    But then you either paste it in with the corrct offset or use Find & Replace



+ 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