VBA: Search for text in row & copy last cell/row in that column

Eyes0ftheworld

New Member
Joined
Apr 23, 2014
Messages
28
Hi!

I have a list of search terms in Sheet1 starting at A1. The length of the list varies. I need it to loop through that list of search terms & search Sheet2 for those terms. The terms will be somewhere in row 10 of Sheet2. Once it finds a match, I need it to find the last row in that column and copy that cell & paste value in Sheet2, column K in the next black row.
I know this is kind of complicated, but I'm struggling with it.

Thanks!
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,096
Try:
Code:
Sub CopyCell()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Sheets("Sheet1").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim Lastrow2 As Long
    Dim Term As Range
    Dim foundTerm As Range
    For Each Term In Sheets("Sheet1").Range("A1:A" & LastRow)
        Set foundTerm = Sheets("Sheet2").Rows(10).Find(Term, LookIn:=xlValues, lookat:=xlWhole)
        If Not foundTerm Is Nothing Then
            Lastrow2 = Sheets("Sheet2").Cells(Rows.Count, foundTerm.Column).End(xlUp).Row
            Sheets("Sheet2").Cells(Lastrow2, foundTerm.Column).Copy
            Sheets("Sheet2").Cells(Rows.Count, "K").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
            Application.CutCopyMode = False
        End If
    Next Term
    Application.ScreenUpdating = True
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,193
Messages
5,594,774
Members
413,934
Latest member
austinb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top