+ Reply to Thread
Results 1 to 8 of 8

Delete everything before certain text

  1. #1
    Registered User
    Join Date
    12-15-2012
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    4

    Delete everything before certain text

    Hi All

    Thanks for having a look at my problem, its 1 in the morning and I'm a little brain fried, perhaps you may be able to give me some guidance as I'm fairly new to programming macros in Excel.

    Basically I have a range of data typically B11 to N50 which may contain text which will need manipulation based on the contents.

    The only text I need to manipulate will be between 7 and 11 characters long and always have "(SWP)" in the middle.
    examples would look like XXX(SWP)YYY otherwise I want to leave things as they are.

    I want to do is to delete everything before the Y YY or YYY (ie after the (SWP) characters).

    Does that make any sense.

    Looking forward to any help you may be able to give me.
    Thanks
    Andy

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Delete everything before certain text

    why not just find/replace?
    find (swp)*
    replace with (swp)
    buy im not sure what you want to keep
    I
    want to do is to delete everything before the Y YY or YYY (ie after the (SWP) characters).
    do you want to keep
    xxx(swp)
    xxx
    yyyy
    or
    (swp)yyyyy
    in any of those case you can use the* wild card
    xxx(swp) find (swp)* replace (swp)
    xxx find (swp)* replace with nothing
    yyyy find *(swp) replace with nothing
    or
    (swp)yyyyy find *(swp) replace (swp)
    Last edited by martindwilson; 12-15-2012 at 10:06 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Delete everything before certain text

    hmm forum playing up again must be backup time
    Last edited by martindwilson; 12-15-2012 at 09:56 PM.

  4. #4
    Registered User
    Join Date
    12-15-2012
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Delete everything before certain text

    ok

    So XXX and YYY can be random 1, 2 or 3 character text seperated by the text (SWP) within a certain range of cells;
    other cells within the same range can contain other data which I dont want to manipulate.

    I don't quite get how I can find and replace when I don't know what the cell will contain other than within the cell there will be the (SWP) text.

    Thanks
    Andy

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Delete everything before certain text

    see my post #2 use the * wild card as shown (i was updating it as you posted)
    Last edited by martindwilson; 12-15-2012 at 10:11 PM.

  6. #6
    Registered User
    Join Date
    12-15-2012
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Delete everything before certain text

    Sorry looks like the forum backup was causing me a few viewing issues.
    Thanks
    Andy

  7. #7
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Delete everything before certain text

    Agree with Martin on this one, Find/Replace is easiest method...

    If you ever wanted to create a macro that would do the same thing, just turn on the macro recorder and take the steps you wold need to perform the replacement manually, then stop the recorder and check out the VBA to see how it is set up.

    Below, I did just that:
    Please Login or Register  to view this content.
    Or, you could loop through each cell in the range and do the same...
    Please Login or Register  to view this content.
    Lots of ways to do these things... but I would still go with the old Find/Replace as Martin suggested.

    - Moo

  8. #8
    Registered User
    Join Date
    12-15-2012
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Delete everything before certain text

    Thanks both.
    I was trying to over engineer the process.
    All works fine.
    Cheers
    Andy

+ 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