+ Reply to Thread
Results 1 to 10 of 10

VBA for searching string in a column and copy rows depending on string in adjacent cell

  1. #1
    Registered User
    Join Date
    10-16-2012
    Location
    Seoul, Korea
    MS-Off Ver
    Excel 2013, Excel 2016
    Posts
    14

    Post VBA for searching string in a column and copy rows depending on string in adjacent cell

    I am completely new for VBA. I have excel data sheet containing numbers and strings. I want to search for certain string say 'CYP' in column 'I' then look for a cell of its row at column 'C' and copy entire rows containing the string of cell 'C'. I want to paste in sheet 2 of the same workbook and loop it again to look for remaining CYPs in column 'I'. (I have attached a problem file sample with desired result in the attachment.)

    Would you help me on this please?
    Attached Files Attached Files
    Last edited by xprakash; 10-19-2013 at 10:14 PM.

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VBA for searching string in a column and copy rows depending on string in adjacent cel

    Hi xprakash,

    Welcome the forum!!

    Let us know how this goes:

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    10-16-2012
    Location
    Seoul, Korea
    MS-Off Ver
    Excel 2013, Excel 2016
    Posts
    14

    Re: VBA for searching string in a column and copy rows depending on string in adjacent cel

    Thank you Robert,
    The code copied all the rows having CYP in row. It is really great but what I wanted was a step further.
    If there is the presence of CYP in any cell of column I, I want it to check a cell of the same row at column C and copy all the rows containing exactly the same string as in that cell to paste on sheet2 and loop this action until the search for cyp at column I reaches to the end of the column.

    Any ideas?

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VBA for searching string in a column and copy rows depending on string in adjacent cel

    So the first matching row in Sheet1 is 2. Do you then want all the matching entries for ADF45 (this is in cell C2) copied to Sheet2. If so, what happens with Row 3 as the code in cell C3 is again ADF45? This will mean that all the cells with ADF45 will in fact be copied 4 times as there's an overall total of 4 matches?

    Perhaps if you could post the desired results in a separate tab it will make things clearer.

    Robert

  5. #5
    Registered User
    Join Date
    10-16-2012
    Location
    Seoul, Korea
    MS-Off Ver
    Excel 2013, Excel 2016
    Posts
    14

    Re: VBA for searching string in a column and copy rows depending on string in adjacent cel

    Quote Originally Posted by Trebor76 View Post
    So the first matching row in Sheet1 is 2. Do you then want all the matching entries for ADF45 (this is in cell C2) copied to Sheet2.
    Yes, it is exactly what I want.
    Quote Originally Posted by Trebor76 View Post
    If so, what happens with Row 3 as the code in cell C3 is again ADF45?
    I want it to look for CYP in column I only after the last row it copied and loop the action as above.
    Quote Originally Posted by Trebor76 View Post
    Perhaps if you could post the desired results in a separate tab it will make things clearer.
    I have attached a file with desired result tab in my original question (thread) above.
    Thank you

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VBA for searching string in a column and copy rows depending on string in adjacent cel

    You didn't answer the second question i.e. what happens when the same title is found in column C

    In any case, I think you only want show the title from column C once, so see how this goes:

    Please Login or Register  to view this content.
    Robert

  7. #7
    Registered User
    Join Date
    10-16-2012
    Location
    Seoul, Korea
    MS-Off Ver
    Excel 2013, Excel 2016
    Posts
    14

    Re: VBA for searching string in a column and copy rows depending on string in adjacent cel

    Thank you again Robert. But this macro copied the first row with CYP at column 'I for every row with same string at a cell in column C of same row. Would you modify it testing with the file attached above please?

  8. #8
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VBA for searching string in a column and copy rows depending on string in adjacent cel

    Thank you again Robert. But this macro copied the first row with CYP at column 'I for every row with same string at a cell in column C of same row. Would you modify it testing with the file attached above please?
    Yes, by changing this line of code...

    Please Login or Register  to view this content.
    ...to this:

    Please Login or Register  to view this content.
    should do the job.

    Regards,

    Robert

  9. #9
    Registered User
    Join Date
    10-16-2012
    Location
    Seoul, Korea
    MS-Off Ver
    Excel 2013, Excel 2016
    Posts
    14

    Re: VBA for searching string in a column and copy rows depending on string in adjacent cel

    Wow! Thank you very much Robert. It did a trick

  10. #10
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VBA for searching string in a column and copy rows depending on string in adjacent cel

    That's great

    If you could please mark the thread as solved it would be appreciated.

    Regards,

    Robert

+ 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. 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
  2. copy rows in sheet2 if certain cells in column x has a string
    By greatalex36 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-18-2012, 11:09 AM
  3. Replies: 12
    Last Post: 09-15-2012, 10:20 PM
  4. how to find Certain String in a column, select/Copy the cell till another String
    By excelkeechak in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-18-2009, 10:59 AM
  5. Searching for a string in a cell, and then creating a Sheet for that string
    By vmc62 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-22-2008, 12:07 PM

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