Delete Rows

  • Thread starter Thread starter John Keturi
  • Start date Start date
J

John Keturi

This looks in column 6 (date column), and supposedly removes those rows
which do not meet the user input date. Ie; users input is 1/1/2003, so this
deletes all rows prior to 1/1/2003. However, I get a run time error on the
line "a.EntireRow.Delete" What does this mean? Thanks

Sub DeleteDates()
Dim TempString As String
TempString = InputBox("Enter beginning Date", "Beginning of Date
Range")
If Not TempString = "" Then
msg = "Removing Data prior to - " & TempString & " , Are you Sure
this is the Correct Date?"
DialogStyle = vbYesNo + vbExclamation + vbDefaultButton1
Title = "Is this the Correct Date?"
Response = MsgBox(msg, DialogStyle, Title)
End If
If Response = vbYes Then
GoTo DeleteData
Else
GoTo Aborted
End If
DeleteData:
For a = 2 To 1000
If Cells(6, a).Value < TempString Then a.EntireRow.Delete
Next
Aborted:
End Sub
 
Hi John,
suppose you have 3 rows
delete row 1
delete row 2 which had been row 3
delete row 3 not found

you have to delete (or insert) rows in reverse order
delete row 3
delete row 2
delete row 1

For a = 1000 to 2 step -1
...
Next a
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top