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:
- Open the Excel workbook and press Alt + F11 to open the Visual Basic Editor.
- In the Project Explorer window, double-click on the sheet where you want to add the code (in this case, the "Register" sheet).
- In the code window, select Worksheet from the left drop-down menu and Change from the right drop-down menu.
- 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
===========================
- 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.