Macro sends all rows to other sheet instead of just the one which is being checked

temdream

New Member
Joined
Mar 17, 2021
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
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
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
To iterate simply, i would really appreciate a VBA code which sends an entire row to a different sheet when the contents of one of it's cells is changed. Thank you very much in advance once again,
.
 
Upvote 0

Forum statistics

Threads
1,223,935
Messages
6,175,493
Members
452,649
Latest member
mr_bhavesh

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