Move rows based on 2 different values

kanderson83

New Member
Joined
Feb 7, 2020
Messages
4
Office Version
  1. 2013
Platform
  1. Windows
I am trying to have rows automatically move to different sheets based on 2 different values. I want the row to move once "resolved" but I want it to move to a specific sheet based on the partner. I am currently using this code below to have the rows move automatically from the "currently working" sheet to the "resolved " sheet. Instead of moving to resolved, I would like them to move to a sheet based on the partner name in column "C."

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    Application.EnableEvents = False
    'If Cell that is edited is in column G and the value is resolved then
    If Target.Column = 7 And Target.Value = "Resolved" Then
        'Define last row on resolved worksheet to know where to place the row of data
        LrowResolved = Sheets("Resolved").Cells(Rows.Count, "A").End(xlUp).Row
        'Copy and paste data
        Range("A" & Target.Row & ":H" & Target.Row).Copy Sheets("Resolved").Range("A" & LrowResolved + 1)
        'Delete Row from Project List
        Range("A" & Target.Row & ":H" & Target.Row).Delete xlShiftUp
    End If
    Application.EnableEvents = True
End Sub
 
Last edited by a moderator:
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Column = 4 Then
      If LCase(Target.Value) = "accepted" Then
         With Target.EntireRow
            .Copy Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
            .Delete
         End With
      ElseIf LCase(Target.Value) = "rejected" Then
         With Target.EntireRow
            .Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
            .Delete
         End With
      End If
   End If
End Sub
The code is case insensitive, so it doesn't matter how it's entered into the sheet.

Thank you for your very prompt response, it works brilliantly. I was going wrong by not having 'Elseif' in line 9 of the code.
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You're welcome & thanks for the feedback
 
Upvote 0
You're welcome & thanks for the feedback

No problem, I appreciate the support more knowledgeable people (like yourself) pass on to a complete novice like me. If I wanted to also move columns marked as "withdrawn" as well as 'rejected' to the same sheet (Sheet3) can I just add to the first line of the block of code below or would I have to copy the complete bit of code below and add it to the bottom and change the Target.Value to "withdrawn".

VBA Code:
      ElseIf LCase(Target.Value) = "rejected" Then
         With Target.EntireRow
            .Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
            .Delete
         End With
 
Upvote 0
You can just add that to the ElseIf line
VBA Code:
      ElseIf LCase(Target.Value) = "rejected" Or LCase(Target.Value) = "withdrawn" Then
 
Upvote 0
You can just add that to the ElseIf line
VBA Code:
      ElseIf LCase(Target.Value) = "rejected" Or LCase(Target.Value) = "withdrawn" Then
That's brilliant thank you, it works a treat.
 
Upvote 0
My pleasure & thanks for the feedback
 
Upvote 0
Hello, I am new here and haven't really worked with VBA in the last 15 years solid. Could you please help me with this exact scenario, except
to simply move the lines to the bottom of the current sheet?
 
Upvote 0
Please start a thread of your own, giving full details of what you want.
Thanks
 
Upvote 0

Forum statistics

Threads
1,215,056
Messages
6,122,907
Members
449,096
Latest member
dbomb1414

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