Move row into worksheet after entry of worksheet name into row using VBA in Microsoft Excel

Question:
When entering a sheet name in column D, the row of the entry is to be moved to the respective sheet

Answer:
Insert the following code in the This Workbook module.

 
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim wks As Worksheet
   Dim intRow As Integer
   If Target.Column <> 4 Then Exit Sub
   If IsEmpty(Target) Then Exit Sub
   On Error Resume Next
   Set wks = Worksheets(Target.Value)
   If Err > 0 Or wks Is Nothing Then
      MsgBox "Sheet name Not Found!"
      Exit Sub
   End If
   On Error GoTo 0
   With wks
      intRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
      .Range(.Cells(intRow, 1), .Cells(intRow, 3)).Value = _
         Range(Cells(Target.Row, 1), Cells(Target.Row, 3)).Value
   End With
   Rows(Target.Row).Delete
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.