+ Reply to Thread
Results 1 to 9 of 9

Search for string, then cut and paste the string to a new cell

  1. #1
    Registered User
    Join Date
    02-11-2010
    Location
    Maryland, USA
    MS-Off Ver
    Excel 2007
    Posts
    83

    Question Search for string, then cut and paste the string to a new cell

    Hello again everyone!

    I have inherited an Excel spreadsheet that contains information in Column A cells that I'd like to search for and then cut it from the rest of the string and paste it to another cell. Here's an example spreadsheet for the sake of context:

    Example.xlsx

    I need to write a formula/macro/script that searches through each cell in column A for a specified term ( e.g. "expert report" or "deposition exhibit"), and that then cuts the text in the string from the preceding "(" through the next ")". The cut text would then be pasted into the same row in column D. So if I ran the macro on the above table searching for the term "expert report" the resulting table should look like this:

    Example 2.xlsx

    I'm familiar with programming generally, but not specifically with macros and VBA in Excel. Can anyone help me out on this?

    THANK YOU!!!
    Rob

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Search for string, then cut and paste the string to a new cell

    The rules change with each cells information. If you were taking data from in front of the key word or after the key word you could do this this , but you are trying to take different length strings (inclusive) in front of the key word. I honestly don't see how you can do this?
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Search for string, then cut and paste the string to a new cell

    If the data was always in the format you present you could use the following code but I share the previous sentiments in that this may not be robust enough as the rules may not always apply. Do not run this on real data as you cannot undo VBA. I tried results with "expert report" and "deposition exhibit" (you do not have to enter the words in upper/lower case - it does not matter) and it outputs correctly. See attached workbook - there is copy of your results and a spare copy raw data for you to test it. Essentially the search terms would have to be within parentheses.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by smuzoen; 06-23-2012 at 05:28 AM.
    Hope this helps.
    Anthony
    Pack my box with five dozen liquor jugs
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated?

  4. #4
    Registered User
    Join Date
    02-11-2010
    Location
    Maryland, USA
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Search for string, then cut and paste the string to a new cell

    [QUOTE=smuzoen;2834857] Essentially the search terms would have to be within parentheses.
    [code]

    Thank you both! Fortunately, the search string does always appear within parenthesis. I'll give this a shot and let you know how it turns out.

    THANK YOU AGAIN!
    Rob

  5. #5
    Registered User
    Join Date
    02-11-2010
    Location
    Maryland, USA
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Search for string, then cut and paste the string to a new cell

    Works perfectly. I can't thank you enough! I have a follow-up question... How is the script determining where to paste the copied string? I'd like to be able to change the column where it is pasting if I need to.

    Thanks again!

  6. #6
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Search for string, then cut and paste the string to a new cell

    The code is looking in Column A for the string to examine. In this case cells(row, column) - so 1 in this case is Column A
    Please Login or Register  to view this content.
    So it then pastes the results into Column 1 and into Column 4 (Column D)
    Please Login or Register  to view this content.
    So just change the 4 to whatever column you want the results added to. Substitute 1 for the column with the data to search and 4 for the column where you want the extracted results to go.
    Just one thing to add is if there is a bit of data to process add the following to stop screen flicker.
    Please Login or Register  to view this content.
    I hope that answers your question.
    Last edited by smuzoen; 06-23-2012 at 06:28 AM.

  7. #7
    Registered User
    Join Date
    02-11-2010
    Location
    Maryland, USA
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Search for string, then cut and paste the string to a new cell

    Absolutely incredible. Thank you, you have saved me hours of manual cut and paste work.

    On a completely different note, can you recommend a really good book on Excel? I'm interested in having a reference nearby when I need to figure out formulas, and I'd like to become proficient in scripting.

    Thanks again!
    Rob

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search for string, then cut and paste the string to a new cell


  9. #9
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Search for string, then cut and paste the string to a new cell

    I must admit I have a few e-Books but I rarely use them - I am more inclined to work on the premise "Google is Your Friend". If you have a question chances are the question has been asked many time before. The forum here can be searched and has some of the best Excel Gurus you could hope to find. However here are some links that I would recommend.
    There is a Sticky on the front page of this forum http://www.excelforum.com/excel-prog...materials.html

+ 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