Move rows to another sheet based on cell value- VBA

sassyGuava

New Member
Joined
Jul 25, 2018
Messages
1
I'm very new to VBA and I'm trying to automate some processes via Excel.
I have a workbook with 3 sheets:
Ship
In Transit
Delivered
I would like to be able to move the rows from Ship to In Transit or Delivered based on a value in the "W" column. If the value is In Transit to move it to the next empty row in the In Transit worksheet. If the value is Delivered to move it to the next empty row in the Delivered worksheet.
I would appreciate any help or any pointers in the right direction!!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try this:
This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab Named Ship
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

This script copies the row to the other sheet.
You said Move. Not sure if that means copy to other sheet and then delete from sheet named Ship or not. If you want it deleted also from sheet Ship you will have to let me know.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  7/25/2018  8:20:48 PM  EDT
If Not Intersect(Target, Range("W:W")) Is Nothing Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Dim r As Long
Dim Lastrow As Long
Dim ans As String
ans = Target.Value
r = Target.Row
Lastrow = Sheets(ans).Cells(Rows.Count, "W").End(xlUp).Row + 1
Rows(r).Copy Sheets(ans).Rows(Lastrow)
End If
End Sub
 
Last edited:
Upvote 0
If you do want the row deleted use this script:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  7/25/2018  8:36:41 PM  EDT
If Not Intersect(Target, Range("W:W")) Is Nothing Then
Application.EnableEvents = False
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Dim r As Long
Dim Lastrow As Long
Dim ans As String
ans = Target.Value
r = Target.Row
Lastrow = Sheets(ans).Cells(Rows.Count, "W").End(xlUp).Row + 1
Rows(r).Copy Sheets(ans).Rows(Lastrow)
Rows(r).Delete
End If
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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