Forum Discussion
cwenos97
Nov 13, 2019Copper Contributor
Excel VBA help
I have a document containing data that I would like to have moved to another sheet when it is marked "Y" for completed. The completed column is J, the original sheet is called 2020 Projects and ...
Subodh_Tiwari_sktneer
Nov 13, 2019Silver Contributor
Place the following Change Event Code on 2020 Projects Sheet Module.
To do so, right click on the 2020 Projects Sheet Tab --> View Code and paste the code given below into the opened code window.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
Dim wsDest As Worksheet
Dim r As Long
Dim dlr As Long
Application.ScreenUpdating = False
On Error GoTo Skip
'Setting the destination Worksheet
Set wsDest = Worksheets("Completed Projects")
'Assuming the header row is Row2, data starts from Row3 and the completed column is Column J
If Target.Column = 10 And Target.Row > 2 Then
If Target = "Y" Then
Application.EnableEvents = False
r = Target.Row
dlr = wsDest.Cells(Rows.Count, "J").End(xlUp).Row + 1
With Range("A" & r & ":J" & r)
.Copy wsDest.Range("A" & dlr)
.Delete shift:=xlUp
End With
End If
End If
Skip:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
cwenos97
Nov 13, 2019Copper Contributor
ISubodh_Tiwari_sktneer is the
Private Sub Worksheet_Change(ByVal Target As Range)
required to be the in the header? I cannot figure out how to save this macro with that header.
When running the macro without that header I get a Run time error '424'; Object required error.
- Subodh_Tiwari_sktneerNov 14, 2019Silver Contributor
Please find attached a dummy file with the code on 2020 Projects Sheet Module for your reference.
Also, refer to the below images to know how you should proceed in order to implement this code to your workbook.
Step1:
Step2:
After the above step, a code window will be popped up as shown below.