Move a row based on drop down list to another sheet

Anonymous
2024-01-12T14:17:26+00:00

Hi I have a spreadsheet that i would like to be able to automatically move a row to another sheet based on the selection from a drop down menu. As you can see in the screenshot below, the column with the drop down is Status (col I). There is a drop down list that entries correspond to the names of the worksheets. eg If I select "Zone1" in the column the whole row (Cols A-M) will automatically move to the worksheet "Zone1". The original entry does not stay in the "Register" sheet. Then if I want to move the row again I would go to where the record is located and the same thing happens when I change the status.

Please I am not a VBA expert so I need small steps!

Thanks in anticipation!

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2024-01-12T16:28:07+00:00

    Here are the steps to create a VBA code that will move a row to another sheet based on the selection from a drop-down menu:

    1. Open the Excel workbook and press Alt + F11 to open the Visual Basic Editor.
    2. In the Project Explorer window, double-click on the sheet where you want to add the code (in this case, the "Register" sheet).
    3. In the code window, select Worksheet from the left drop-down menu and Change from the right drop-down menu.
    4. Copy and paste the following code into the code window:

    ======================================

    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim ws As Worksheet
    
    Dim rng As Range
    
    Dim lastRow As Long
    
    'Check if the changed cell is in column I (Status)
    
    If Target.Column = 9 Then
    
        'Get the selected worksheet name
    
        Set ws = Worksheets(Target.Value)
    
        'Get the last row in the selected worksheet
    
        lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1
    
        'Copy the row to the selected worksheet
    
        Set rng = Range("A" & Target.Row & ":M" & Target.Row)
    
        rng.Copy ws.Range("A" & lastRow)
    
        'Delete the row from the Register sheet
    
        rng.Delete Shift:=xlUp
    
    End If
    

    End Sub

    ===========================

    1. Save the workbook and close the Visual Basic Editor.

    Now, whenever you change the value in column I (Status), the code will check if the selected worksheet exists and copy the row to that worksheet. It will also delete the row from the "Register" sheet. Note that the code assumes that the worksheet names in the drop-down list match the actual worksheet names in the workbook. If there is no matching worksheet, the code will generate an error.

    3 people found this answer helpful.
    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2024-01-13T08:26:42+00:00

    Thank you so much for your help! It worked exactly how I hoped. I am about to post another question....you may be able to help me there too!

    0 comments No comments
  2. Anonymous
    2024-01-13T14:52:04+00:00

    You are wlecome. I will try.

    0 comments No comments
  3. Anonymous
    2024-01-30T03:46:29+00:00

    I tried using this code for a different data range in column G on my own workbook and nothing happens.

    Can you help?

    0 comments No comments
  4. Anonymous
    2024-01-30T05:13:50+00:00

    Share a test workbook.

    0 comments No comments