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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

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,903
Office Version
365
Platform
Windows
Status
Not open for further replies.

Watch MrExcel Video

Forum statistics

Threads
1,102,778
Messages
5,488,819
Members
407,658
Latest member
Arias610

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top