VBA to cut and paste a row into another sheet if one of the cells meets criteria.

TJKnight

New Member
Joined
Sep 24, 2020
Messages
4
Office Version
  1. 2013
Platform
  1. Windows
I run a warehouse and we are getting ready to ramp up the volume of orders we receive from our customer. I want the sheet to cut the entire row and paste it into the next sheet anytime the dropdown box in column "I" is changed to yes.
Excel pic.PNG
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Welcome to the Board!

What is the name of the sheet you want to paste this row too?
 
Upvote 0
OK, right-click on the sheet tab name at the bottom of the screen, select "View Code", and then paste this code in the resulting VB Editor window that pops up.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim ows As Worksheet
    Dim nws As Worksheet
    Dim lr As Long
    
'   Set name of worksheet to copy to, and name of current sheet
    Set nws = Sheets("QA")
    Set ows = ActiveSheet
    
'   Exit if more than one cell updated
    If Target.CountLarge > 1 Then Exit Sub
    
'   Check to see if row > 1 and value is "Yes"
    If (Target.Row > 1) And (Target.Value = "Yes") Then
'       Find first blank row on new sheet
        lr = nws.Cells(Rows.Count, "A").End(xlUp).Row + 1
'       Copy to new sheet
        Application.EnableEvents = False
        ows.Rows(Target.Row).Copy nws.Cells(lr, "A")
'       Delete old row
        ows.Rows(Target.Row).Delete
        Application.EnableEvents = True
    End If

End Sub
This should do what you want automatically upon changing the value in column I.
 
Upvote 0
Thank you so much!!! Now if I want it to move out of the QA sheet in to the Ready to ship sheet do I use the same code except for the "Set nws = sheets ("QA") part?
 
Upvote 0
Now if I want it to move out of the QA sheet in to the Ready to ship sheet do I use the same code except for the "Set nws = sheets ("QA") part?
Yes, but make sure that you put the code in the correct place. It will not go in the same place as the first code, but rather in the "QA" sheet module in VBA.
(In order for these event procedures to work automatically, they must be placed in the proper sheet modules, and must be named a certain way).
 
Upvote 0
You are most welcome.
Glad I was able to help!
:)
 
Upvote 0
Hello,

I am doing some work on excel and the above information was brilliant, i do have a query to take it one step further though.
If i was using a front sheet for what i will call "live jobs" and i wanted the function above but for it to apply to multiple tabs is there a way to do this? So when 'yes' its typed in Column I it went to various other tabs (i.e customer 1, customer 2, Customer 3) depending on where they were sitting in the spreadsheet?
 
Upvote 0
Welcome to the Board!

You would have to explain this part in more detail:
So when 'yes' its typed in Column I it went to various other tabs (i.e customer 1, customer 2, Customer 3) depending on where they were sitting in the spreadsheet?
in order that we have know how to determine which sheet to paste it to.

Posting a sample of how your sheet and the data is structured would probably be helpful here.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,985
Members
452,540
Latest member
haasro02

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