+ Reply to Thread
Results 1 to 2 of 2

Search column for string and return every row with that string in new sheet

  1. #1
    Registered User
    Join Date
    07-03-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Search column for string and return every row with that string in new sheet

    Hi All,

    I want to search column B for "Dog" and return then copy every row with "Dog" in column B to a new sheet. The solution would be to return AB in A1, Red Dog in B1, CD in A2, and Blue Dog in B2. This example is much simpler, but you can see my progress in the code below:

    Please help!

    Sub search_Click()
    Dim strFind As String
    Dim NextRow As Long
    Dim rngFound As Range
    Dim wsSource As Worksheet, wsResult As Worksheet

    Set wsSource = Sheets("Sheet1")
    Set wsResult = Sheets("Sheet2")

    With wsSource
    strFind = .Range("C2").Value
    Set rngFound = .Range("B1:B15000").Find(What:=strFind, LookAt:=xlPart)
    If Not rngFound Is Nothing Then
    NextRow = wsResult.Range("B" & Rows.Count).End(xlUp).Row + 1
    rngFound.EntireRow.Copy wsResult.Range("A" & NextRow)
    End If
    End With

    End Sub

    AB Red Dog
    CD Blue Dog
    EF Yellow Cat

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Search column for string and return every row with that string in new sheet

    Try this AutoFilter code, which will be much faster than a Find-FindNext loop. You need to put column headings in row 1 of the source sheet for this method to work.
    Please Login or Register  to view this content.
    Obviously the Criteria1:="=*dog*" part can be modified to use a search string in a cell.
    Post responsibly. Search for excelforum.com

+ 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