Move a row to a different sheet based on a cell value

pyclen

Board Regular
Joined
Jan 17, 2022
Messages
85
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi there,

to quote to Dr. Strange (not verbatim though), Dormammu, I have come again for advice.

I have a tracker w/multiple sheets, one is called NEW, one is Completed and one is Cancelled, there is also a lists tab for drop down menus. This is a mockup of a file I am using for work.

My question is:
Can I move a row where I have flipped the status from NO to either Yes, or Cancelled to the corresponding tab, i.e. when I set the cell in N2 to Yes, the whole row should move to COMPLETED, or if N2 = Cancelled to the Cancelled tab.
I also need to have the rows insert beneath the last row on either the Completed or Cancelled tab. I have both other tabs copied below (1st is completed, 2nd is cancelled, just look at column N if unclear)

And finally, when the row gets moved I would like to get rid of the formatting in column B which is based on a priority

Thank you again for helping out a noob who is trying to improve processes left behind.

example tracker.xlsx
ABCDEFGHIJKLMN
1Date receivedPriorityCompanyBD ContactLeadQuotation NumberSF InquiryProject decriptionTypeRebidTarget completion dateActual completion dateNotesCompleted2
220-Jun-221abc LtdMikeJohnQ12345675-1234make carsquotationno25-Jun-22make enough carsNo
320-Jun-222dfg inc.AshleyJohnQ12345775-1235make dummiesquotationyes28-Junmake enough dummiesNo
421-Jun-221dfg inc.AshleyJohnQ12345875-1236make enginesquotationno30-Junmake enough enginesNo
522-Jun-221jung llcHeidiCassiopeiaQ12345975-1237make seatsquotationno29-Junmake enough seatsNo
623-Jun-222lan llcLarryMeganQ12346075-1238make windowsquotationno24-Junmake enough windowsNo
724-Jun-222abc LtdMikeJohnQ12346175-1239make wheelsquotationno27-Junmake enough wheelsNo
825-Jun-22on holdabc LtdMikeJohnQ12346275-1240make more carsCost Estimateno29-Junmake way more carsNo
New
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B2:B8Cell Value="on hold"textNO
B2:B8Cell Value=2textNO
B2:B8Cell Value=1textNO
Cells with Data Validation
CellAllowCriteria
N2:N8List=Completion
D2:D8List=BD
E2:E8List=Lead
I2:I8List=Type



Date receivedPriorityCompanyBD ContactLeadQuotation NumberSF InquiryProject decriptionTypeRebidTarget completion dateActual completion dateNotesCompleted
15-Jun-221abc LtdMikeJohnQ12345675-1234make carsquotationno19-Jun-2219-Junmake enough carsYes



Date receivedPriorityCompanyBD ContactLeadQuotation NumberSF InquiryProject decriptionTypeRebidTarget completion dateActual completion dateNotesComplete
15-Jun-221zxT, LLCAshleyMeganQ12345675-0023make rubber hosequotationno19-Jun-2219-Junmake enough carsCancelled
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
So, you're saying if Range("N2").value says "COMPLETED" you want this row copied to a sheet Named "Completed" Or if Cancelled copy Row to sheet named "Cancelled"

And this will only apply to Range ("N2")
Never N4 or N5

Is this correct?
And do not copy formatting

And this script runs automatically when you enter the value into Range("N2")
 
Upvote 0
So, you're saying if Range("N2").value says "COMPLETED" you want this row copied to a sheet Named "Completed" Or if Cancelled copy Row to sheet named "Cancelled"

And this will only apply to Range ("N2")
Never N4 or N5

Is this correct?
And do not copy formatting

And this script runs automatically when you enter the value into Range("N2")
What I want to do is when I flip the cell in column N (can be 2, 3, 4 etc.) to either completed or cancelled that the whole row (A2-N2 or A4-N4 etc) moves to the corresponding tab.

Additionally, when the whole row moves that all formatting is removed although that is secondary, the whole row moving to a different tab is more important.

Hope this helps
 
Upvote 0
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
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

When you enter Completed or Cancelled in Column N the script will run

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  6/20/2022  10:32:12 PM  EDT
If Target.Column = 14 Then
On Error GoTo M
Dim Lastrow As Long
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Dim r As Long
Dim ans As String
r = Target.Row
ans = Target.Value
Lastrow = Sheets(ans).Cells(Rows.Count, "N").End(xlUp).Row + 1
Rows(r).Copy: Sheets(ans).Rows(Lastrow).PasteSpecial xlPasteValues
Application.CutCopyMode = False
'If you want the original row deleted from the original sheet remove the ' from in front of next line of code
'Rows(r).delete
End If
Exit Sub
M:
MsgBox "We had a problem " & vbNewLine & "You entered " & Target.Value & vbNewLine & "There is no sheet by that name"
End Sub
 
Upvote 0
Thank you very much as that indeed does the trick. The only change I need is to have the message box/error not appear when something else is chosen in Column N.
My choices are in progress, on hold, completed and cancelled, and with the above script I get errors when I select in progress or on hold.

When I select either in progress or on hold I do not need to have anything done, only with completed and cancelled do I need to have the rows moved.

I tried to remove the line with on error goto M as well as the lines below w/M: and the MSgBox but it gives an error in row 9 (starts w/ LastRow=......)

Again, thank you for the help, really appreciated
 
Upvote 0
Try this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  6/21/2022  9:31:35 AM  EDT
If Target.Column = 14 Then
On Error GoTo M
Dim Lastrow As Long
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Dim r As Long
Dim ans As String
r = Target.Row
ans = Target.Value
Select Case Target.Value
Case "Completed", "Cancelled"
Lastrow = Sheets(ans).Cells(Rows.Count, "N").End(xlUp).Row + 1
Rows(r).Copy: Sheets(ans).Rows(Lastrow).PasteSpecial xlPasteValues
Application.CutCopyMode = False
'If you want the original row deleted from the original sheet remove the ' from in front of next line of code
'Rows(r).delete
End Select
End If
Exit Sub
M:
MsgBox "We had a problem " & vbNewLine & "You entered " & Target.Value & vbNewLine & "There is no sheet by that name"
End Sub
 
Upvote 0
Solution
Thank you much, sir, I really appreciate the help, and I am amazed with the skills of people on this board

great resource and board
 
Upvote 0
Thank you much, sir, I really appreciate the help, and I am amazed with the skills of people on this board

great resource and board
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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