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!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,882
Members
449,097
Latest member
dbomb1414

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
Back
Top