Re: Can I do this to excel?
Yes, I think this can all be done in regular VBA in Excel ... you don't need .Net. You shouldn't need anything else. There have been a lot of posts iterating through rows in a Worksheet, but if you need to see it again, just let us know. What you need to define thoroughly is what constitutes a valid row that you do not want to delete, and it looks like you've done that.
You also will need to know what exactly your formula is going to do. Are you only doing this operation one time, or will this be done every month?
Re: Can I do this to excel?
This should get you started. I'm assuming that an empty cell in column D means that the row is invalid ... you'll have to make sure that whatever you decide is definitive for identifying a row as valid or invalid.
Code:
Option Explicit
Sub Macro1()
Dim i As Long
Dim aRow As Long
Dim lastRow As Long
Dim aRange As Range
Dim aCell As Range
'You need to know the inclusive range of the source sheet
'This is just for a quick test ...
Set aRange = Range("D1:D7") '<< this just searches column "D"
lastRow = aRange.Rows.Count 'Find the end row to check
'Iterate through all rows deleting 'invalid' rows
'From your examples,
' I am assuming that an empty cell in column "D" means an invalid row
aRow = 1
For i = 1 To lastRow
If IsEmpty(Cells(aRow, "D").Value) Then
'TEST TEST TEST TEST
MsgBox Cells(aRow, "D").Address & " is not valid"
'END TEST
Rows(aRow).Delete Shift:=xlUp
Else
aRow = aRow + 1
End If
Next i
End Sub
Search the Forum for a function "ActualUsedRange" for identifying the real range occupied by data.