+ Reply to Thread
Results 1 to 8 of 8

Extracting strings of text from cells

  1. #1
    Registered User
    Join Date
    08-23-2010
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003
    Posts
    25

    Extracting strings of text from cells

    I have a worksheet with column A filled with miscellaneous data. For example, A1 may contain "Nike shoes 1977 699999993335 black shoe laces" (without quotations). I need to go through the data and somehow find "1977" (year of make) and "Nike" (type of shoe) and "black shoe laces" for color of laces. I could then place these categories in a new column (b, c, d). The problem is vlookup does not work well for sifting through this data. I have approximately 10,000 different categories (years, type of shoes, color of laces) to search for throughout column A and place into columns b, c, and d. Here is some code I use just fine for cells which contain only what I am looking for (such as black shoe laces or 1977):
    Please Login or Register  to view this content.
    As you can see, the lookup list is quite large, but will not work with cells which have multiple words and numbers. Any help would be much appreciated.

    I have attached a spreadsheet to convey a general idea of what is to be accomplished. All phrases to be used are found on sheet 2. No phrases outside of these parameters will be necessary--so if a person describes his shoes as "1988 Scottie Pippen Red Hounders" then the Red Hounders would not be important because it is not contained on sheet 2.

    Thanks
    Attached Files Attached Files
    Last edited by drcheaud; 08-23-2010 at 10:57 PM. Reason: added code tags

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Sifting through a string of text

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    If your data is in a consistent format, then how about text to columns. If it is varied then how about attaching an example file, showing your raw data, and how / why it should be split out.

    rylo

  3. #3
    Registered User
    Join Date
    08-23-2010
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003
    Posts
    25

    How to find a specific text within textstring and place in adjacent column

    Basically, I am looking to take the texts in column A and look for exact matches from sheet 2. Any help at how to get started would be much appreciated. Thanks. By the way, there are thousands of these "raw" texts I will need to go through--thus the need for a program like a formula or VB code.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Extracting strings of text from cells

    Hi

    This will get most of what you are chasing. You could build your arrays from reference data, but I've just hard coded things to give an example.

    Please Login or Register  to view this content.
    HTH

    rylo

  5. #5
    Registered User
    Join Date
    08-23-2010
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Extracting strings of text from cells

    This looks great. How would I incorporate a referenced array of data--say A2:B50--in place of the hard written potions?

  6. #6
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Extracting strings of text from cells

    Hi

    As your array only needs to have one side of things something like
    Please Login or Register  to view this content.
    rylo

  7. #7
    Registered User
    Join Date
    08-23-2010
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Extracting strings of text from cells

    This is working very well for the most part. I am now having issues when trying to incorporate the ranges from sheet2. The error I get is on the Instr function for the shoelaces:

    Sub air()
    shoearr = Range(Range("Sheet2!C2"), Range("Sheet2!C2").End(xlDown))
    lacearr = Array("White Shoe Laces", "Black Shoe Laces", "Yellow Shoe Laces", "Green Shoe Laces", "Brown Shoe Laces", "Blue Shoe Laces", "Red Shoe Laces")
    specarr = Array("Air Jordan", "Kobe Bryant", "Pumps", "Shaqs", "Nike Air", "Long", "Full tongue")
    For Each ce In Range("A2:A50")
    arr = Split(ce.Value, " ")
    'assumes year is only numeric in string
    For i = LBound(arr) To UBound(arr)
    If IsNumeric(arr(i)) Then[/COLOR] ce.Offset(0, 1).Value = arr(i)
    Next i
    'shoe type
    For i = LBound(shoearr) To UBound(shoearr)
    If InStr(1, ce, shoearr(i)) > 0 Then ce.Offset(0, 2).Value = shoearr(i)
    Next i
    'lace type
    For i = LBound(lacearr) To UBound(lacearr)
    If InStr(1, LCase(ce), LCase(lacearr(i))) > 0 Then ce.Offset(0, 3).Value = lacearr(i)
    Next i
    'special type
    For i = LBound(specarr) To UBound(specarr)
    If InStr(1, LCase(ce), LCase(specarr(i))) > 0 Then ce.Offset(0, 4).Value = specarr(i)
    Next i
    Next ce
    End Sub
    The error states the subscript is out of range. What am I missing? Thanks ahead.

  8. #8
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Extracting strings of text from cells

    Hi

    Notice the revised structure of the array call when using the range.

    Please Login or Register  to view this content.
    rylo

+ 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