+ Reply to Thread
Results 1 to 7 of 7

Parsing text to columns

Hybrid View

basic Parsing text to columns 12-01-2010, 06:09 PM
GaidenFocus Re: Parsing text to columns 12-01-2010, 06:44 PM
JBeaucaire Re: Parsing text to columns 12-01-2010, 06:58 PM
basic Re: Parsing text to columns 12-01-2010, 07:33 PM
Leith Ross Re: Parsing text to columns 12-02-2010, 02:07 AM
JBeaucaire Re: Parsing text to columns 12-02-2010, 10:43 AM
basic Re: Parsing text to columns 12-02-2010, 01:46 PM
  1. #1
    Registered User
    Join Date
    12-01-2010
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2007
    Posts
    3

    Question Parsing text to columns

    Just started wondering if there's a simpler way to do this, I basically need to manually scrape information from text files and enter into excel. I've usually done it all by hand which takes a good long while.

    Source plain-text input:
    CUSTOMER NAME - [0a-00-3e-f5-2e-63] - LUID: 006
    CUSTOMER NAME (CONTACT), (780) xxx-xxxx - [0a-00-3e-f6-ea-2a] - LUID: 009
    CUSTOMER NAME (CONTACT) (780) xxx-xxxx - [0a-00-3e-f6-ea-30] - LUID: 007
    CUSTOMER NAME - [0a-00-3e-f2-0c-f1] - LUID: 008
    CUSTOMER NAME (Abbreviated) - [0a-00-3e-f7-4d-7e] - LUID: 010
    CUSTOMER NAME (CUSTOMER SITE - NAME) - [0a-00-3e-d0-b5-de] - LUID: 003
    CUSTOMER NAME, (780)xxx-xxxx cell. - [0a-00-3e-d0-b6-05] - LUID: 002
    CUSTOMER NAME - [0a-00-3e-fa-81-45] - LUID: 005
    CUSTOMER SITE - CUSTOMER NAME - [0a-00-3e-d0-b5-fe] - LUID: 004

    Final Excel output after copying each item by hand ('|' is a separated column):
    CUSTOMER NAME |0a-00-3e-f5-2e-63|
    CUSTOMER NAME (CONTACT) |0a-00-3e-f6-ea-2a|
    CUSTOMER NAME (CONTACT) |0a-00-3e-f6-ea-30|
    CUSTOMER NAME |0a-00-3e-f2-0c-f1|
    CUSTOMER NAME (Abbreviated) |0a-00-3e-f7-4d-7e|
    CUSTOMER NAME (CUSTOMER SITE - NAME) |0a-00-3e-d0-b5-de|
    CUSTOMER NAME |0a-00-3e-d0-b6-05|
    CUSTOMER NAME |0a-00-3e-fa-81-45|
    CUSTOMER SITE - CUSTOMER NAME |0a-00-3e-d0-b5-fe|

    As you can imagine this is quite tedious after awhile.

    It's the same thing I want to apply on each tab/sheet, but could always make it so its all in one sheet if that's easier. Any ideas?
    Last edited by basic; 12-02-2010 at 03:09 PM. Reason: 2 Great solutions, closing as solved

  2. #2
    Forum Contributor
    Join Date
    10-08-2010
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    386

    Re: Parsing text to columns

    i suggest going to the DATA tab and playing around with the TEXT TO COLUMNS feature.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Parsing text to columns

    Text To Columns one the way to go but your data doesn't seem to have a good consistent delimiter to use.

    Put the data in column A.

    Put this formula in B1:
    =LEFT(A1,FIND("[", A1)-4)

    Put this in C1:
    =MID(A1, FIND("[", A1) +1, 17)

    Drag those two formulas down. Is that usable?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    12-01-2010
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Parsing text to columns

    Awesome! is there anyway I can get rid of the source column A and just keep the accurate B & C columns?

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Parsing text to columns

    Hello basic,

    This macro will separate the data into 2 columns: A and B. The example workbook has a button on "Sheet1" to run the macro.
    'Thread: http://www.excelforum.com/excel-programming/755186-parsing-text-to-columns.html
    'Poster: basic
    'Written: December 01, 2010
    'Author:  Leith Ross (www.excelforum.com & www.thecodecage.com)
    
    Sub ParseData()
    
      Dim Cell As Range
      Dim Rng As Range
      Dim RegExp As Object
      Dim S As String
      Dim T As Boolean
      Dim X As String
      
        Set Rng = Worksheets("Sheet1").Range("A1:A9")
        
        Set RegExp = CreateObject("VBScript.RegExp")
        RegExp.IgnoreCase = True
        RegExp.Pattern = "([\w\-\s\(]+)(?:\)|\,|\s\-).+\[(.+)\].*"
        
          For Each Cell In Rng
            S = Cell.Value
            If RegExp.Test(S) Then
              X = RegExp.Replace(S, "$1")
                If InStr(1, X, "(") Then Cell.Value = X & ")" Else Cell.Value = X
              Cell.Offset(0, 1).Value = RegExp.Replace(S, "$2")
            End If
          Next Cell
          
        Rng.Resize(ColumnSize:=2).EntireColumn.AutoFit
        
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Parsing text to columns

    Quote Originally Posted by basic View Post
    Awesome! is there anyway I can get rid of the source column A and just keep the accurate B & C columns?
    Yes, after dragging down your formulas, highlight columns B and C, copy, then use Edit > paste special > Values to remove the formulas. Then you can delete column A.

  7. #7
    Registered User
    Join Date
    12-01-2010
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Parsing text to columns

    Wow! look how that works... I also like the solution Leith Ross has but I found out it doesn't co-operate with the & sign well like CUSTOMER NAME & CUSTOMER NAME. Also for some reason the macro script only parses the first 9 values. JBeaucaire's solution is also good I can't see a problem with it.

    This is cool I can start flying through this stuff now ^_^

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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