+ Reply to Thread
Results 1 to 4 of 4

UDF to Split Text String

  1. #1
    Registered User
    Join Date
    01-27-2010
    Location
    South Carolina
    MS-Off Ver
    Excel 2003
    Posts
    1

    UDF to Split Text String

    I am trying to take data from a table in a pdf. and transfer it to an excel spreadsheet that I will then add to a GIS database. Two different types of data are presented in 2 different formats. I need to remove unnecessary data from each format while maintaining the necessary data and splitting the necessary data into separate columns. Here are the two examples:

    1) This may be easier because the two pieces of data I need are always the first and last pieces of data. In some cases there is more data in the cell than others including other numbers. I have included the two primary examples of how it appears below along with examples of how the data should appear afterwards.

    (Data in 2 rows/1column)
    BP Borrow pits 72.00
    FuB Fuquay fine sand, 0 to 6 percent slopes 114.00

    (Remaining data in 2 rows/2 columns, Text and numbers in different columns)
    BP 72
    FuB 114

    So you can see I'm splitting BP and 72 into separate columns and deleting "Borrow pits". In the second example I'm splitting FuB and 114 into separate columns and deleting "Fuquay fine sand, 0 to 6 percent slopes".

    2) In this one I need to do the same but the placement and type of data is different. The first part is the same. I need to retain the code at the beginning of the string in the 1st column. In the second column I just need whether it is Very Limited, Somewhat Limited, or Not Limited. Here are three examples of data strings. Each would be in a single cell.

    (Data in 3 rows/1 column)
    BP Borrow pits Very limited Udorthents 0.9
    BrA Brogdon loamy sand, 0 to 2 percent slopes Not limited Brogdon 1
    Ca Cantey loam Somewhat limited Cantey 1

    Here's how the resulting data would look:

    (Remaining data in 3 rows/2 columns, data split between code and very, not or somewhat limited)

    BP Very Limited
    BrA Not Limited
    Ca Somewhat Limited

    Note: I could use a numeric code (1,2,3) for Very Limited, Not Limited, and Somewhat Limited as I'll eventually have to convert it to that anyway if that makes it any easier.

    Thanks in advance for any help you can provide.

  2. #2
    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: Need Function (UDF) to Split Text String In a Complicated Way

    Hi, and welcome to the forum.

    An attached workbook with a few examples of the results you expect is worth a thousand words.
    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.

  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: UDF to Split Text String

    This aren't UDFs, they are reformatting macros. Run this on a copy of your values in column A and see if they do what you wish.

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 01-27-2010 at 01:32 PM.
    _________________
    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
    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: UDF to Split Text String

    Hello cdrhodes,

    Welcome to the Forum!

    If you have a large amount of data to parse then this solution will provide you with fast processing. This macro looks at the data on "Sheet1" column "A" and parses the strings. The parsed data is copied to "Sheet2" starting in cells A1 and B1. You can change the worksheet names, starting cell of the source sheet and the starting row of the destination sheet. These are marked in the code in red.
    Please Login or Register  to view this content.
    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time.
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
    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!)

+ 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