View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
jasontferrell jasontferrell is offline
external usenet poster
 
Posts: 56
Default Delete Specific Rows Using VBA

If the regional settings of your computer are set for dd/mm/yyyy
format, then Excel should be able to convert the string returned by
the inputbox correctly. Try this, but you should clean up the
"activesheet" references so that users cannot change the active sheet
mid-process and end up with an unexpected result.

Public Sub DeleteRows()
Dim sDate As String, lRow As Long, lCount As Long
sDate = InputBox("Please enter the date")
If IsDate(sDate) Then
lRow = 2
For lCount = 2 To ActiveSheet.UsedRange.Rows.Count
If ActiveSheet.Cells(lRow, 7).Value < DateValue(sDate)
Then
ActiveSheet.Cells(lRow, 7).EntireRow.Delete
Else
lRow = lRow + 1
End If
Next lCount
Else
MsgBox sDate & " does not appear to be a valid date"
End If
End Sub