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:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Is the value in col C the same as the worksheet name?
Also what happens if the sheet doesn't exist?
 
Upvote 0
Value in C is the same as the worksheet name. MXCCM, Credico, Sprint Direct

Could I keep the resolved sheet in the case that a sheet doesn't exist? Or in that case, could it stay on the "currently working" page?
 
Upvote 0
Ok, how about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim Ws As Worksheet
   On Error GoTo Xit
   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
      If Evaluate("isref('" & Target.Offset(, -4).Value & "'!A1)") Then
         Set Ws = Sheets(Target.Offset(, -4).Value)
      Else
         Set Ws = Sheets("Resolved")
      End If
         'Define last row on resolved worksheet to know where to place the row of data
         LrowResolved = Ws.Cells(Rows.Count, "A").End(xlUp).Row
         'Copy and paste data
         Range("A" & Target.Row & ":H" & Target.Row).Copy Ws.Range("A" & LrowResolved + 1)
         'Delete Row from Project List
         Range("A" & Target.Row & ":H" & Target.Row).Delete xlShiftUp
      End If
   End If
Xit:
   Application.EnableEvents = True
End Sub
 
Upvote 0
1581100208898.png

I get this error
 
Upvote 0
Oops, delete one of these End If lines
Rich (BB code):
         Range("A" & Target.Row & ":H" & Target.Row).Delete xlShiftUp
      End If
   End If
Xit:
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
I think what I'm trying to achieve is the similar to the original post, but apologies if it isn't. I'm using the code below to move rows marked as 'accepted' (column 4) to a different sheet (sheet2). I would like to add more code into this to move rows marked as 'rejected' (column 4) to another sheet (sheet3). I just don't know what to do.

Also how to get the macro to accept all cases in the target cell (not just lower case)??

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 4 And Target.Cells.Count = 1 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
        End If
    End If
End Sub

Many thanks in advance for your help
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,495
Members
449,088
Latest member
Melvetica

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