2 macros - Copy Row and Cut and paste row to another worksheet based on value

Bloople

New Member
Joined
Aug 7, 2020
Messages
25
Office Version
  1. 2016
Platform
  1. Windows
Afternoon all

I've been working on a spreadsheet. I had no VBA knowledge at all, now I still have close to none! I've been searching various forums and websites and copied and pasted code in a trial and error way, sometimes successfully, sometimes not. I'm stuck now though. I've seen lots of similar questions and experimented with the answers provided, but can't get it to work.

I want two macros to run on my workbook. One is for when a city is chosen from a drop down menu, that row gets copied into the corresponding city worksheet. Secondly, when 'Completed' is chosen from a drop down menu on another column, I want that row to be moved to the Completed spreadsheet.


I've got the following code:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range) 
If Target.Column = 6 Then 
tRow = Target.Row 
Range("F" & tRow).EntireRow.Copy Sheets("London").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) 
Range("F" & tRow).EntireRow.Copy Sheets("Manchester").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) 
Range("F" & tRow).EntireRow.Copy Sheets("Leeds").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) 
Range("F" & tRow).EntireRow.Copy Sheets("Birmingham").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) 
Range("F" & tRow).EntireRow.Copy Sheets("Cardiff").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) 
End

If Application.EnableEvents = False 

If Target.Column = 9 Then 
tRow = Target.Row 
Range("I" & tRow).EntireRow.Delete Sheets("Completed").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) 
End If 
Application.EnableEvents = True

End Sub

The city part works fine. The second part only deletes the row. I want it copied and pasted first, then delete, or just moved. I can't work out what code to add in though and how.
 
Lcase converts the cell value to lower case, that way it doesn't matter if you have completed, Completed, COMPLETED, or any other variation, it will still work.
So had you change the code?
If so, you should always tell people that.
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Lcase converts the cell value to lower case, that way it doesn't matter if you have completed, Completed, COMPLETED, or any other variation, it will still work.
So had you change the code?
If so, you should always tell people that.

Oh I'm sorry. With yours, I changed completed to COMPLETED as that's what I had in my list for the Overview sheet. But then I put it back to lowercase completed and it worked. So your code as your wrote it did work.
 
Upvote 0

Forum statistics

Threads
1,223,990
Messages
6,175,816
Members
452,672
Latest member
missbanana

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