+ Reply to Thread
Results 1 to 15 of 15

Find and move text

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    MS-Off Ver
    365
    Posts
    172

    Question Find and move text

    I have a series of data where I need to take the text at the end and place at the front. I would be most grateful if anyone can help. Below is an example of the data - it does not require to be case sensitive and any spaces can be removed.

    Many thanks

    123*1232abc needs to be: abc123*1232
    145x14587 ED needs to be ED145x14587
    548 x 5874 x 256 awd needs to be awd548 x 5874
    Last edited by Tellm; 10-10-2011 at 05:02 PM.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Find and move text

    For the first two examples, assuming they appear in cell A1, the following would work ...

    =TRIM(RIGHT(A1,3)) & TRIM(LEFT(A1,LEN(A1)-3))

    However, your third example seems to suggest that you want text after the second "x" taken out - is that correct?

  3. #3
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    MS-Off Ver
    365
    Posts
    172

    Re: Find and move text

    Andrew

    Sorry that was an error - the data after the second x should also be there.

    Thanks

  4. #4
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    MS-Off Ver
    365
    Posts
    172

    Re: Find and move text

    Andrew, I am again sorry as I didn't give a full explanation on the original post. The data will change every-time I use it, as it is copied in from others file. So the formula needs to identify how many letters are at the end and to put them at the front.

  5. #5
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Find and move text

    OK, still assuming your original value is in A1, try ...

    =TRIM(LEFT(RIGHT(A1,MATCH(FALSE,INDEX(ISERROR(VALUE(MID(A1,(LEN(A1)+1)-ROW(INDIRECT("A1:A" & LEN(A1))),1))),0),0)-1) & A1,LEN(A1)))

  6. #6
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    MS-Off Ver
    365
    Posts
    172

    Re: Find and move text

    Andrew I'm getting an error in the formula at the point (LEN(A1)+1) the LEN is highlighted. As I have absolutely no idea what I am looking at I'm stuck

  7. #7
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Find and move text

    Could you post an example workbook? My formula works for me, so I'll need to see what you're trying to convert.

  8. #8
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    MS-Off Ver
    365
    Posts
    172

    Re: Find and move text

    Andrew

    Please find attached a sample file with what I am trying to achieve. I have manually entered sample data in column G what I am trying to get to.
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Find and move text

    Ah, I take it you're using Excel 2003. It's giving an error because it doesn't allow nesting of formula deeply enough for the method I'm using.

    I can write a user-defined function, if you want, but it will depend on macros being enabled in the workbook.

  10. #10
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    MS-Off Ver
    365
    Posts
    172

    Re: Find and move text

    You're correct with your assumption that I'm using 2003. I have macro's enable to bring the data in so I'll use whatever you can provide to get this to work - many thanks.

  11. #11
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Find and move text

    OK, this function should work fine as a worksheet function. It's not the neatest in the world, but seems to work OK for me ...

    Function TextToFront(ByVal sFullString As String) As String
    
    Dim lFindLoop
    
    On Error GoTo ExitFunction
    
    lFindLoop = Len(sFullString)
    
    If lFindLoop > 0 Then
      While lFindLoop > 0 And Not (IsNumeric(Mid(sFullString, lFindLoop, 1)))
        lFindLoop = lFindLoop - 1
      Wend
    End If
    
    ExitFunction:
    
    If lFindLoop = 0 Then
      TextToFront = sFullString
    Else
      TextToFront = Mid(sFullString, lFindLoop + 1) & Left(sFullString, lFindLoop)
    End If
    
    End Function

  12. #12
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    MS-Off Ver
    365
    Posts
    172

    Re: Find and move text

    Andrew - thanks for this - the question is how do I get this function to work?

  13. #13
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Find and move text

    Open your workbook.

    Press Alt-F11 to open the VB editor

    From the Insert menu select "Module"

    A new module will open and you can paste my code straight in.

    On your workbook you can now use =TEXTTOFRONT as a worksheet function, so if the value 123abc is in cell A1 then using =TextToFront(A1) in another cell will return abc123.

  14. #14
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    MS-Off Ver
    365
    Posts
    172

    Re: Find and move text

    Andrew I am still having problems - I have followed your instruction to the letter but I now get a #Name? error within the cell.

  15. #15
    Forum Contributor
    Join Date
    11-28-2005
    Location
    Dover, England
    MS-Off Ver
    365
    Posts
    172

    Re: Find and move text

    Andrew - disregard my last - everything is fine - many many thanks for all you have done

+ 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