+ Reply to Thread
Results 1 to 4 of 4

Search multiple values in a column and copy found rows plus one row below to a new sheet

  1. #1
    Registered User
    Join Date
    05-16-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Search multiple values in a column and copy found rows plus one row below to a new sheet

    Hey Guys!

    I am a noob in VBA and I am trying to create a macro which will search for multiple values in a column and will copy the found rows plus the two rows below each found row to a new sheet within the same workbook. Here is how the source sheet looks like:

    In this example I will search for words Pear and Blackberry (the search will always be done in Column D) the code has to find the keywords and copy the found row where the words are (there can be thirty Pear and twenty Blackberry keywords in the column and the macro has to be able to loop and find and copy all the words in the column), in this case it's Row4 and Row10 copy I need to copy them plus the copy has to add 2 additional rows below referencing to the found keywords (in this case Rows 4 to 6 and Rows 10 to 12 need to be copied and pasted into a new sheet).

    Source:

    A B C D
    Row1 1. Apple Carrot Cucumber
    Row2 Vegetable
    Empty Row3
    Row4 2. Apple Potato Pear
    Row5 Fruit
    Empty Row6
    Row7 3. Melon Carrot Potato
    Row8 Vegetable
    Empty Row 9
    Row10 4. Cherry Orange Blackberry
    Row11 Berry
    Empty Row12


    Result:

    A B C D
    Row1 1. Apple Potato Pear
    Row2 Fruit
    Empty Row3
    Row4 2. Cherry Orange Blackberry
    Row5 Berry
    Empty Row6

    I found this macro and modified it a bit. It does what I need but it doesn't copy the 2 rows below to the referencing row. Please help me with the code.

    Please Login or Register  to view this content.

    Thanks a bunch guys!
    Last edited by sadyr; 03-31-2014 at 12:19 PM.

  2. #2
    Forum Contributor
    Join Date
    01-30-2013
    Location
    Wales
    MS-Off Ver
    Excel 2013
    Posts
    231

    Re: Search multiple values in a column and copy found rows plus one row below to a new she

    Amend the line with:-

    Rows(x & ":" & x).Select

    to :-
    Rows(x & ":" & x+2).Select
    Click * below if this answer helped

  3. #3
    Registered User
    Join Date
    05-16-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Search multiple values in a column and copy found rows plus one row below to a new she

    Hey Chris53! Thanks so much! It was fast and so simple ! It Worked!

    But there is one but. I added as you suggested and it copies just one additional row below not two row below. I need the empty row to be copied and pasted into the new sheet too.
    Any suggestions?

    And I appreciate your prompt response!

  4. #4
    Registered User
    Join Date
    05-16-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Search multiple values in a column and copy found rows plus one row below to a new she

    Hey Chris, nevermind, I figured it out thanks to you help!

    You need add additional row to copy, so the code looks like:

    If Cells(x+1, 4) = "Pear" Or Cells(x+1, 4) = "Blackberry" Then
    Rows(x & ":" & x+2).Select

    Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Search for multiple rows and copy them into a new sheet
    By Moggelito in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-25-2014, 08:50 AM
  2. Search string in a column then copy entire rows to another sheet
    By vannylette in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-12-2013, 12:16 PM
  3. [SOLVED] Search for a value in a column and copy row to new sheet for all matching values
    By mrcois in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-20-2012, 12:09 PM
  4. Search for Multiple String Values on Multiple Sheets and Copy Rows to New Sheet
    By rrtikker in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-15-2012, 12:21 PM
  5. Search for multiple string values and copy row to new sheet
    By steeley7 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-12-2011, 04:00 AM

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