+ Reply to Thread
Results 1 to 5 of 5

Selective text to column?

  1. #1
    Registered User
    Join Date
    05-30-2012
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    4

    Selective text to column?

    Hi everyone, I'm new the forums, and very new to using Excel VBE. I'm not too sure about its limitations and I may ask stupid questions, please be patient with me haha. Also if I'm being unclear on anything just let me know and I'll clarify. Thanks in advance for your help!

    So let's simplify and say my worksheet just has 1 column and 50,000 rows. All the cells are filled with something like "000001-ABC_DEF_BLAH All_NEW HELLO WORLD_15x15", the main thing I have to do with A1 through A50,000 is to use text to column to get rid of the useless first number, in that example it should end up returning "000001" in A1, and "ABC_DEF_BLAH All_NEW HELLO WORLD_15x15" in B1. Now, if all the cells were in that format, it would be simple to use text to column with delimiter "-" to do so for all rows, but it's never that simple is it

    The problem is that some of the cells don't have the useless number that I'm trying to get rid of. They are filled with values like "ABC_DEF_BLAH All_NEW-HELLO WORLD_15x15" where the "-" is in the middle of the string of text. I know for certain that the beginning number is always 5 or 6 numbers long, and IF the cell doesn't carry the useless number, and has a "-" in the middle, the "-" is never in the first 7 characters. Is there a way to use a macro to text to column selectively JUST if there is a "-" in the first 7 characters?

    Thanks again and if I need to clarify anything please let me know!

    -Derek

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: Selective text to column?

    have you tried to use a mid() formula? if you can identify which 1st part you want to discard...or which middle part you want to keep, we could put something together that may help?

    a sample file with either some representative examples...or some actual data if its not sensitive...would help us to help you better
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Selective text to column?

    Hi, and welcome to the forum.

    Rather than text to columns you could use two functions - there's probably a smaller more elegant one around the corner but it's getting late here...

    B1:
    =IF(ISERROR(FIND("-",LEFT(A1,7))),"",LEFT(A1,FIND("-",LEFT(A1,7))-1))
    C1:
    =IF(ISERROR(FIND("-",LEFT(A1,7))),A1,RIGHT(A1,LEN(A1)-FIND("-",LEFT(A1,7))))
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    05-30-2012
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Selective text to column?

    Thanks for the prompt replies guys, and Richard that worked pretty much perfectly, really appreciate the help guys!

    So unfortunately I realized I was wrong and that not all the useless numbers are followed by "-", some of them aren't followed by any symbols before going into the ABC parts, and some other useless numbers are followed by "_" or some other symbols. Richard's functions takes care of 98% of the 50,000 rows, which is awesome, but is there a way to take care of all the useless numbers in one stroke?

    I guess a cleaner way to think about it is if the data in the cell begins with a number, get rid of that number AND any symbols immediately after the number and leave anything else. If the data in the cell begins with a useless number and is followed immediately by letters, then only get rid of the number. If it doesn't begin with a number we don't need to touch anything. Thanks again and sorry about the mistake!

    -Derek

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Selective text to column?

    Hello Derek,

    If the alpha characters are all capital letters, how about

    B1:
    =MID(A1,MATCH(TRUE,ISNUMBER(1*MID(A1,ROW($1:$9),1)),0),COUNT(1*MID(A1,ROW($1:$9),1)))

    C1:
    =RIGHT(A1,1+LEN(A1)-MATCH(1,(CODE(MID(A1,ROW($A$1:$A$255),1))<=90)*(CODE(MID(A1,ROW($A$1:$A$255),1))>=65),FALSE))

    Both of these are array formula and should be entered with Ctrl-Shift-Enter

+ 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