Automatically move cell lines to multiple sheets

JessicaKinnear

New Member
Joined
Jan 6, 2021
Messages
25
Office Version
  1. 365
Platform
  1. Windows
Hello, first off please bare with me if this is a stupid question, this is my first time ever putting any code in so I am very much a beginner.

On my spreadsheet I would like to be able to use the function 'If the data in column 8 contains "ü" then move it to sheet 2 and delete the row', but I'd also like it to do 'If the data in column 9 contains "ü" then move it to sheet 3 and delete the row.

I found a previous post where someone wrote the code for just actioning one point e.g.:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 8 And Target.Cells.Count = 1 Then
        If LCase(Target.Value) = "ü" Then
            With Target.EntireRow
                .Copy Sheets("sheet 2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                .Delete
            End With
        End If
    End If
End Sub

So I thought I could just copy and paste the above below but change the numbers from 8 to 9 and the sheet from 2 to 3 see below:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 8 And Target.Cells.Count = 1 Then
        If LCase(Target.Value) = "ü" Then
            With Target.EntireRow
                .Copy Sheets("pitches").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                .Delete
            End With
        End If
    End If
End Sub
    If Target.Column = 9 And Target.Cells.Count = 1 Then
        If LCase(Target.Value) = "ü" Then
            With Target.EntireRow
                .Copy Sheets("Dead leads").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                .Delete
             End With
        End If
    End If
End Sub


However I get the comment 'Only comments may appear after End Sub, End Function, or End Property'

Any ideas how I can do this so the sheet runs both actions?

Thank you
 
Last edited by a moderator:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Column = 8 Then
        If LCase(Target.Value) = "ü" Then
            With Target.EntireRow
                .Copy Sheets("pitches").Range("A" & Rows.count).End(xlUp).Offset(1, 0)
                .Delete
            End With
        End If
    ElseIf Target.Column = 9 Then
        If LCase(Target.Value) = "ü" Then
            With Target.EntireRow
                .Copy Sheets("Dead leads").Range("A" & Rows.count).End(xlUp).Offset(1, 0)
                .Delete
             End With
        End If
    End If
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Column = 8 Then
        If LCase(Target.Value) = "ü" Then
            With Target.EntireRow
                .Copy Sheets("pitches").Range("A" & Rows.count).End(xlUp).Offset(1, 0)
                .Delete
            End With
        End If
    ElseIf Target.Column = 9 Then
        If LCase(Target.Value) = "ü" Then
            With Target.EntireRow
                .Copy Sheets("Dead leads").Range("A" & Rows.count).End(xlUp).Offset(1, 0)
                .Delete
             End With
        End If
    End If
End Sub

[/CODE
[/QUOTE]
Perfect - thanks so much!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
You're welcome & thanks for the feedback.
Sorry another question, if I wanted to do exactly the same as above but instead of the cell containing '"ü"', I would like it to move the row if the cell contains any date in the format dd/mm/yyyy. I've tried replacing '"ü" in the code above with '"dd/mm/yyyy" but no luck. - Thanks in advance
 
Upvote 0
Try
VBA Code:
   If Target.Value Like "##/##/####" Then
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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