+ Reply to Thread
Results 1 to 17 of 17

Filtering by list of keywords and pasting results into spreadsheet

Hybrid View

  1. #1
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Filtering by list of keywords and pasting results into spreadsheet

    Try this.
    Sub x()
        Dim rTest       As Range
        Dim rLook       As Range
        Dim rFind       As Range
        Dim sAddr       As String
        Dim iRow        As Long
    
        With Me
            Set rTest = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
        End With
    
        With Sheet2
            Set rLook = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
        End With
    
        For iRow = rTest.Rows.Count To 1 Step -1
            Set rFind = rLook.Find(What:=rTest(iRow).Text, After:=rLook(1), _
                                   SearchDirection:=xlPrevious, _
                                   MatchCase:=False, MatchByte:=False, _
                                   SearchFormat:=False)
            If Not rFind Is Nothing Then
                sAddr = rFind.Address
                
                Do
                    Application.CutCopyMode = False
                    With rTest(iRow, 1)
                        .EntireRow.Copy
                        .Offset(1).Insert
                        rFind.EntireRow.Resize(, Columns.Count - 1).Copy Destination:=.Offset(1, 1)
                    End With
                    Set rFind = rLook.Find(What:=rTest(iRow).Text, After:=rFind, _
                                           SearchDirection:=xlPrevious)
                Loop Until rFind.Address = sAddr
            End If
                
            rTest(iRow, 1).EntireRow.Delete
        Next iRow
        
        Application.CutCopyMode = xlCopy
    End Sub
    Entia non sunt multiplicanda sine necessitate

  2. #2
    Registered User
    Join Date
    07-11-2009
    Location
    -
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: Filtering by list of keywords and pasting results into spreadsheet

    Thanks! That works great.

    I have one more question.
    I would like to speed the process up, I was wondering if rather than going into Sheet 2 and getting each employee row associated to the partial employee name one by one. If it would be possible to filter Sheet 2 by the partial employee name, and cut and paste all those in one swoop into Sheet 1. The output would be the same as the macros you supplied above. I just believe it would speed things up significantly since there are about 600,000 records in Sheet 2 and 3000 partial names in Sheet 1.

    Thanks shg for your help

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Filtering by list of keywords and pasting results into spreadsheet

    Sure, that would be another approach.

    Turning screenupdating off during execution would speed the existing code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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