VBA help to copy rows when key words are selected

steve400243

Active Member
Joined
Sep 15, 2016
Messages
429
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello, I use the below code to transfer rows from the "LOG" Tab to the "RTN HISTORY" tab when "SCRAP", or "RELEASED" in Col Z is selected from the drop down. My question is how would I have it transfer back to the LOG tab if "HOLD" is selected from the dropdown? Thanks for all help.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("Z:Z")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Application.ScreenUpdating = False
Dim Lastrow As Long
Lastrow = Sheets("RTN HISTORY").Cells(Rows.Count, "Z").End(xlUp).Row + 1
    If Target.Value = "SCRAP" Then
        Rows(Target.Row).Copy Destination:=Sheets("RTN HISTORY").Rows(Lastrow)
        Application.EnableEvents = False
        Rows(Target.Row).Delete
        Application.EnableEvents = True
        Exit Sub
    End If
Application.EnableEvents = True
    If Target.Value = "RELEASED" Then
        Rows(Target.Row).Copy Destination:=Sheets("RTN HISTORY").Rows(Lastrow)
        Application.EnableEvents = False
        Rows(Target.Row).Delete
    End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Never Mind all, it was easier than I thought once I slowed down and thought about it..

Code:
Private Sub Worksheet_Change(ByVal Target As Range)If Not Intersect(Target, Range("Z:Z")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Application.ScreenUpdating = False
Dim Lastrow As Long
Lastrow = Sheets("LOG").Cells(Rows.Count, "Z").End(xlUp).Row + 1
    If Target.Value = "HOLD" Then
        Rows(Target.Row).Copy Destination:=Sheets("LOG").Rows(Lastrow)
        Application.EnableEvents = False
        Rows(Target.Row).Delete
        Application.EnableEvents = True
        Exit Sub
    End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,377
Members
448,955
Latest member
BatCoder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top