+ Reply to Thread
Results 1 to 13 of 13

Extract Text From String that contains <cr> with a Macro

  1. #1
    Registered User
    Join Date
    04-28-2009
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2003
    Posts
    7

    Extract Text From String that contains <cr> with a Macro

    I have been given the task of populating a spreadsheet with contact information (e.g. street address, city, zip, phone, fax). I am looking up the info on a web site and copying it as formatted and pasting it into a cell of a spreadsheet. There are seven lines of data and data from six of them goes into a different cells. I also have to ignore some of the data.

    I recorded my keystrokes into a Macro using Relative References. The data gets put in the correct cells but the macro also remembers all the data. This results in the same data in all the cells. Did I do something wrong? Is this possible using a Macro for this task? Also, is there anohter way? I thought of an array but am not skilled enough to know how to do this without spending too much time on it.

    This entire job will take about 10 hours if toally manual. If I can shave off 5 or 6 hours, I'm all for it. So far, I have already spend an hour too much trying to figure out why the Macro isn't working *simle*

    I tried this in Excel 2003 and 2007.

    Any help would be appreciated.

    Example of Cell text after paste from web, before Macro is run:

    123 any street --> in cell a6
    Anytown, IL 65656 --> ignore
    555-666-6789 --> in cell a7
    District Office:--> ignore
    345 another street suite 111 --> in cell a9
    Other Town, IL 65656 --> in cell a10, ignore ", IL" and put zip in a11
    444-333-2121 --> in cell a12

  2. #2
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Extract Text From String that contains <cr> with a Macro

    could you provide some sample data?
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  3. #3
    Registered User
    Join Date
    04-28-2009
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Extract Text From String that contains <cr> with a Macro

    Example data is in my original post. The text is red describes how I want to manipulate the data. Let me know if you need something else.

  4. #4
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394

    Re: Extract Text From String that contains <cr> with a Macro

    Quote Originally Posted by napergman View Post
    Example data is in my original post.
    What DGagnon means is post your spreadsheet that has the data in it and the macro so someone can help you.

  5. #5
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Extract Text From String that contains <cr> with a Macro

    with some source data as well please. its hard to advise how to correct without knowing being able to isolate a problem

  6. #6
    Registered User
    Join Date
    04-28-2009
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Extract Text From String that contains <cr> with a Macro

    Ok, now I understand. See the attached.
    Attached Files Attached Files

  7. #7
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Extract Text From String that contains <cr> with a Macro

    this appears to be the desired output, what is the input data?

  8. #8
    Registered User
    Join Date
    04-28-2009
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Extract Text From String that contains <cr> with a Macro

    The input data is in Column G -- 7 lines of text in 1 cell (G24 and G25). I want to distribute the data to Columns H, J, K, L and M in the same row. See row 23 for desired output.

  9. #9
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Extract Text From String that contains <cr> with a Macro

    Try this, you could also build it into a for/next loop to run through your entire list, but i was not sure of your format, so i set it to only do one row. You can assign this to a keyboard shortcut like your other macros

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    04-28-2009
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Extract Text From String that contains <cr> with a Macro

    Ok, well it worked for one row -- same output as my macro. I may have done something wrong.
    I copied your code and pasted it into my existing macro, replacing all of the existing macro text.
    I put the cursor in the first cell and ran the macro. It populated the rest of the columns of that row and returned the cursor to the next row (correct cell). I ran the macro again and it duplicated the original data set even though the data in the starting cell was different. I then pasted new data into a cell a few rows down and ran the macro again. I got the same data set as the previous two macro runs. Was I supposed to do something different? I think I understand how your code works and it should be independent of the data.

  11. #11
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Extract Text From String that contains <cr> with a Macro

    if it moved the coursor to the next row, you did no run the correct macro... can you please double check that the correct macro is being run. my macro has no commands to move the coursor.

  12. #12
    Registered User
    Join Date
    04-28-2009
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Extract Text From String that contains <cr> with a Macro

    Ok, I'm not sure why it happened but the error was in the way I created the macro. So, how do you create a new macro from scratch? What menu option? I've only recorded a macro.

    So now the macro runs correctly wherever I start it but there are three issues that I need to address.
    1. I don't want to populate column "I"; I want to ignore this data
    2. I only want the first line of the data to remain in column "G"
    3. I want to make the active cell on the next row at column "G" at the end of the macro (next row)

    I have commented out the code to populate column "I" but don't know how to accomplish the other steps. Can you assist one more time. I'd like to know how to move the cursor to the next row, column "g" and would also like to know how to do a for/next loop (if you don't mind).
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 04-07-2012 at 06:07 PM. Reason: Added Code Tags

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Extract Text From String that contains <cr> with a Macro

    Select the cell(s) in Col.G then run the code
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    04-28-2009
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Extract Text From String that contains <cr> with a Macro

    Hello Jindon. Thank you for your solution. It basically works but I need a few other things. See my post from today at 3:23 pm. Can you assist? Thanks

+ 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