Create a macro to find a value in a table, copy the entire row and insert it to a new sheet?

Status
Not open for further replies.

Garrek

New Member
Joined
Aug 22, 2019
Messages
49
I'm looking to create a macro to look up a given value in a table, cut the entire row that the value is in, and paste it at the bottom of a different sheet.

The lookup value is located at cell B14 of Sheet1, it will later be tied to a userform. The table with the list of values in on Sheet2, and the lookup value will always be found in column A of the table. The row lengths vary from 4 cells up to 11. It will be replacing the row onto a table on sheet 3, where I will alphabetize it by column A.

Essentially, Sheet2 contains active items and sheet 3 contains retired items, but it is useful to still have them for reference. Could anyone help with this?
 

Some videos you may like

Excel Facts

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

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,615
Hello,

Does this code work as expected?

Code:
Sub MOVE_TO_SHEET_3()
    Application.ScreenUpdating = False
    With Sheets("Sheet2")
        For MY_ROWS = .Range("A" & .Rows.Count).End(xlUp).Row To 1 Step -1
            If .Range("A" & MY_ROWS).Value = Sheets("Sheet1").Range("B14").Value Then
                .Rows(MY_ROWS).Copy
                Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
                .Rows(MY_ROWS).Delete
            End If
        Next MY_ROWS
    End With
    Application.ScreenUpdating = True
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,614
Office Version
365
Platform
Windows
Status
Not open for further replies.

Watch MrExcel Video

Forum statistics

Threads
1,102,282
Messages
5,485,855
Members
407,521
Latest member
marita

This Week's Hot Topics

Top