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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
11,723
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,898
Messages
5,834,295
Members
430,274
Latest member
TME1993

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