The attached code copies from sheet 1 to sheet 3 all the values that are equal to the value "Moshe" from the table in sheet 1. If rows are added in sheet 1, I want to add only the new rows if they meet the condition
I want to add only the line I marked in yellow
The first line with the entry Moshe has already been added before
I hope that is clear enough .
Sub Moshe()
Dim xRg As Range
Dim xCell As Range
Dim A As Long
Dim B As Long
Dim C As Long
A = Worksheets("sheet1").UsedRange.Rows.Count
B = Worksheets("sheet3").UsedRange.Rows.Count
If B = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("sheet3").UsedRange) = 0 Then B = 1
End If
Set xRg = Worksheets("sheet1").Range("A2:A" & A)
On Error Resume Next
Application.ScreenUpdating = False
For C = 1 To xRg.Count
If CStr(xRg(C).Cells(1, 3)) = "Moshe" Then
xRg(C).EntireRow.Copy Destination:=Worksheets("sheet3").Range("A" & B + 1)
B = B + 1
End If
Next
Application.ScreenUpdating = True
End Sub
I want to add only the line I marked in yellow
The first line with the entry Moshe has already been added before
I hope that is clear enough .
Sub Moshe()
Dim xRg As Range
Dim xCell As Range
Dim A As Long
Dim B As Long
Dim C As Long
A = Worksheets("sheet1").UsedRange.Rows.Count
B = Worksheets("sheet3").UsedRange.Rows.Count
If B = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("sheet3").UsedRange) = 0 Then B = 1
End If
Set xRg = Worksheets("sheet1").Range("A2:A" & A)
On Error Resume Next
Application.ScreenUpdating = False
For C = 1 To xRg.Count
If CStr(xRg(C).Cells(1, 3)) = "Moshe" Then
xRg(C).EntireRow.Copy Destination:=Worksheets("sheet3").Range("A" & B + 1)
B = B + 1
End If
Next
Application.ScreenUpdating = True
End Sub