2017-10-26 6 views
0

以下のコードを微調整して列Aの行データを移動する方法を教えてください。IF文は別のシートにデータを移動しますが、特定の範囲のみを移動します

Private Sub Worksheet_Change(ByVal Target As Range) 
If Target.Column = 11 Then 
    If Target = "Complete" Then 
    nxtRw = Sheets("Completed").Range("A" & Rows.Count).End(xlUp).Row + 1 
    Target.EntireRow.Copy Sheets("Completed").Range("A" & nxtRw) 
    Application.EnableEvents = False 
     Target.EntireRow.Delete shift:=xlUp 
    Application.EnableEvents = True 
    ElseIf Target.Column = 11 Then 
    If Target = "Cancelled" Then 
    nxtRw = Sheets("Completed").Range("A" & Rows.Count).End(xlUp).Row + 1 
    Target.EntireRow.Copy Sheets("Completed").Range("A" & nxtRw) 
    Application.EnableEvents = False 
     Target.EntireRow.Delete shift:=xlUp 
    Application.EnableEvents = True 
    End If 
End If 
End If 
End Sub 

現在のところ、行全体を移動します。そのシートに移動すると、I、J、Kの行に追加の検証リストが表示され、コピーが終了すると削除されます。

すべてのヘルプは非常に

おかげ

マット

答えて

0

リサイズプロパティを使用し理解されたいです。また、Ifを少し短くすることもできます。

Private Sub Worksheet_Change(ByVal Target As Range) 

If Target.Column = 11 Then 
    If Target = "Complete" Then 
     nxtRw = Sheets("Completed").Range("A" & Rows.Count).End(xlUp).Row + 1 
     Cells(Target.Row, 1).Resize(, 8).Copy Sheets("Completed").Range("A" & nxtRw) 
     Application.EnableEvents = False 
     Target.EntireRow.Delete shift:=xlUp 
     Application.EnableEvents = True 
    ElseIf Target = "Cancelled" Then 
     nxtRw = Sheets("Completed").Range("A" & Rows.Count).End(xlUp).Row + 1 
     Cells(Target.Row, 1).Resize(, 8).Copy Sheets("Completed").Range("A" & nxtRw) 
     Application.EnableEvents = False 
     Target.EntireRow.Delete shift:=xlUp 
     Application.EnableEvents = True 
    End If 
End If 

End Sub