I am trying to compare the values ββof cells between 2 sheets (Sheet1 and Sheet2) to see if they coincide, and if they match, move the corresponding values ββin Sheet1 to the pre-existing list (Sheet3) and delete the values ββin Sheet1 after that.
I use the inverse for a loop in Excel VBA, but everything works until I start deleting a row using newrange1.EntireRow.Delete .
This causes the "424" error required by VBA, and I spent hours trying to solve this problem, I'm not sure why this is happening. Am I choosing the wrong line? An object?
I would appreciate it if someone could point me in the right direction.
Here is my code:
Sub Step2() Sheets("Sheet1").Activate Dim counter As Long, unsubListCount As Long, z As Long, x As Long, startRow As Long counter = 0 startRow = 2 z = 0 x = 0 ' Count Sheet3 Entries unsubListCount = Worksheets("Sheet3").UsedRange.Rows.Count Dim rng1 As Range, rng2 As Range, cell1 As Range, cell2 As Range, newrange1 As Range ' Select all emails in Sheet1 and Sheet2 (exclude first row) Set rng1 = Worksheets("Sheet1").Range("D1:D" & Worksheets("Sheet1").UsedRange.Rows.Count) Set rng2 = Worksheets("Sheet2").Range("D1:D" & Worksheets("Sheet2").UsedRange.Rows.Count) ' Brute Loop through each Sheet1 row to check with Sheet2 For z = rng1.Count To startRow Step -1 'Cells(z, 4) Set cell1 = Worksheets("Sheet1").Cells(z, "D") For x = rng2.Count To startRow Step -1 Set cell2 = Worksheets("Sheet2").Cells(x, "D") If cell1.Value = cell2.Value Then ' If rng1 and rng2 emails match counter = counter + 1 Set newrange1 = Worksheets("Sheet1").Rows(cell1.Row) newrange1.Copy Destination:=Worksheets("Sheet3").Range("A" & unsubListCount + counter) newrange1.EntireRow.Delete End If Next Next End Sub
Here is the error I get:

vba excel-vba excel
Kyle yeo
source share