+ Reply to Thread
Results 1 to 6 of 6

How to conditionally insert text string into a line after first word using Word 2010

  1. #1
    Registered User
    Join Date
    12-07-2012
    Location
    London, England
    MS-Off Ver
    Office 2010
    Posts
    81

    How to conditionally insert text string into a line after first word using Word 2010

    I have a lexicon that was created in Word that needs a lot of processing. The data looks like this (this is the actual data, and there's around 200 pages of it so far, with more to come):

    ab ab
    blab (z,d) blab
    dab (z,d) dab
    drab drab
    fab fab
    flab flab
    gab (z,d) gab
    grab (z,d) grab
    jab (z,d) jab
    kab (z,d) cab
    krab (z,d) crab
    lab (z) lab

    Every line should have an item enclosed in brackets after the first word.
    Where this isn't the case, then the following needs to be inserted " (-,-) "

    Everything I've tried so far with find & replace has given very odd results. I'm sure this should be easy, but I can't find the right way to do it, so any hep would be greatly appreciated.
    Last edited by staggers47; 12-08-2012 at 11:06 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    07-27-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    826

    Re: How to conditionally insert text string into a line after first word using Word 2010

    staggers, do you need to keep your data in the order it's in at the moment?
    Brendan.


    __________________________________________________________________________________________________
    Things to consider:

    1) You can thank any poster by clicking the * at the left of a helpful post.
    2) You can help to keep the forum tidy by marking your thread as "Solved", if it has been answered to your satisfaction.
    3) Help us to help you, by uploading a sample workbook, showing the type of data you're dealing with, and clearly indicating what the results should be.

  3. #3
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: How to conditionally insert text string into a line after first word using Word 2010

    Suggest the following.

    Paste Word contents into column A of Excel sheet starting at A1.

    Use the following macro to add edited values to column B. Then paste back into Word.

    Please Login or Register  to view this content.
    Open up the VBA editor by hitting ALT F11

    Insert a new module by hitting Insert - Module

    Paste the macro into the empty sheet

    Hit ALT F11 to get back to the worksheet.

    Run the macro by going to tools-macro in Excel 2003 or the view ribbon in Excel 2007/2010.
    Martin

  4. #4
    Valued Forum Contributor
    Join Date
    07-27-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    826

    Re: How to conditionally insert text string into a line after first word using Word 2010

    Actually, scratch that - you can do the following without interfering with the data order.

    EDIT: Please note that "scratch that" refers to my previous post (#2), and not to mrice's post (#3) which was posted while I was responding. Nice alternative, Martin

    1) Use text to columns to columns (delimited, "space" character separating fields) - your data is now spread across 3 columns: A, B & C.
    2) In D1, enter:

    Please Login or Register  to view this content.
    copied down as far as necessary.

    3) Hide Column C.
    4) Copy the contents of Column D, then paste special --> paste as values into Column D, therefore overwriting the formulas with values.
    5) Filter Column B, excluding anything in brackets.
    6) Now replace the remaining cell contents of Column B with (-,-)
    7) Concatenate the contents of cells as follows: in E1,

    Please Login or Register  to view this content.
    copied down as far as required.

    You should now have your list as you require it.
    Attached Files Attached Files
    Last edited by BB1972; 12-08-2012 at 10:33 AM. Reason: To clarify any potential confusion regarding mrice's post.

  5. #5
    Registered User
    Join Date
    12-07-2012
    Location
    London, England
    MS-Off Ver
    Office 2010
    Posts
    81

    Re: How to conditionally insert text string into a line after first word using Word 2010

    To Martin & Brendan,

    Thanks. Just what I wanted. Worked a treat.

    Martin, you saved me a lot of aggro, so £10 goes into my local Cancer Research shop next week.

    Thanks again to you both.

  6. #6
    Valued Forum Contributor
    Join Date
    07-27-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    826

    Re: How to conditionally insert text string into a line after first word using Word 2010

    staggers,

    Glad you're sorted. Could you please mark you thread "Solved"? Thank you.

+ 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