Greetings everyone, i would like to start out by saying that I have never used VBA and macros until today. Im trying to have a VBA which, when a cell value is changed, copies the entire row to another sheet. The code i am using now, however, all the rows to the next sheet. It was originally a VBA which checks for a value and then pastes the rows which the value to the next sheet, so I tried to change it a bit to make it work for this task but to no success. This is the code i am currently using, would really appreciate if you could help me with a proper code. It looks super messy because i honestly had no idea what i am doing. Thank you very much in advance!
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("M:M")) Is Nothing Then
Dim xRg As Range
Dim xCell As Range
Dim I As Long
Dim J As Long
Dim K As Long
I = Worksheets("Projects").UsedRange.Rows.Count
J = Worksheets("Project Phases").UsedRange.Rows.Count
If J = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("Project Phases").UsedRange) = 0 Then J = 0
End If
Set xRg = Worksheets("Projects").Range("J1:J" & I)
On Error Resume Next
Application.ScreenUpdating = False
For K = 1 To xRg.Count
If CStr(xRg(K).Value) = "Eng Feras" Then
xRg(K).EntireRow.Copy Destination:=Worksheets("Project Phases").Range("A" & J + 1)
J = J + 1
End If
Next
Application.ScreenUpdating = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("M:M")) Is Nothing Then
Dim xRg As Range
Dim xCell As Range
Dim I As Long
Dim J As Long
Dim K As Long
I = Worksheets("Projects").UsedRange.Rows.Count
J = Worksheets("Project Phases").UsedRange.Rows.Count
If J = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("Project Phases").UsedRange) = 0 Then J = 0
End If
Set xRg = Worksheets("Projects").Range("J1:J" & I)
On Error Resume Next
Application.ScreenUpdating = False
For K = 1 To xRg.Count
If CStr(xRg(K).Value) = "Eng Feras" Then
xRg(K).EntireRow.Copy Destination:=Worksheets("Project Phases").Range("A" & J + 1)
J = J + 1
End If
Next
Application.ScreenUpdating = True
End If
End Sub