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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

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

Watch MrExcel Video

Forum statistics

Threads
1,102,206
Messages
5,485,348
Members
407,497
Latest member
astaha

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top