Here is a macro that will delete rows that contain either 409008256 or 210057052 in column D:
Dim rngStart As Range
Dim rngEnd As Range
Dim n As Integer
'set start of data in column D
Set rngStart = Range("D2")
'find end of data in column D
Set rngEnd = Range("D" & CStr(Application.Rows.Count)).End(xlUp)
'work from end of data as deleting rows alters row numbers
For n = rngEnd.Row To rngStart.Row Step -1
'test value in column D
If Range("D" & CStr(n)).Value = 409008256 Or _
Range("D" & CStr(n)).Value = 210057052 Then
'matching value - so select whole row and delete
Range("D" & CStr(n)).EntireRow.Delete
In your macro there were a few issues:
1. The name of the macro matched the name of an existing function (Delete), so it was not accepted.
2. You were testing Cells(datarow, i).Value, but datarow was set to 2 and was never changed and i was counting through rows, but was used as a column value - Cells(row,column).
3. In your test for the numbers you had this - Cells(datarow, i).Value = ("409008256"). This means you were looking for text not an actual number. Also there is no need to place the number in brackets. The use of double quotes denotes that what is inside them is text, even if they look like a number.
4. The delete line - Rows(i - 1).Resize(1).Delete was selecting a single row. The Rows() statement means that you select a single row from the collection of rows on the worksheet - it doesn't select n rows it selects Row n
Then you resized it to one row.
5. Resize uses Resize(Rows,Columns). Whilst it is OK to use the default value of 1 for columns, I prefer to explicitly state the value, then I am less likely to miss the fact that I didn't want 1 column
6. I got a bit lost on what you were trying to achieve with the Do Loop Until part of the macro. I did notice that you used:
Cells(total, 2) which refers to cells in column B, and I wasn't clear why you needed to use column B.
Overall it would help you to document what each part of the code does. It is useful when debugging, but also later if you need to change the macro, it is great to be reminded what the code was doing, rather than trying to work it out from scratch.
PS - I just saw your response
It helps me understand how you ended up with that code :)