if cell is not date format delete row

B

burl_h

I'm having a little trouble with this one, I'm trying to delete all
rows where the cells within the selected range are not formatted as
date.

Sub delete_date()
Dim datarng As Range
lastrow = Cells(Rows.Count, "B").End(xlUp).row
Set datarng = Range ("b2:b" & lastrow)
 
M

Matt Richardson

I'm having a little trouble with this one, I'm trying to delete all
rows where the cells within the selected range are not formatted as
date.

Sub delete_date()
Dim datarng As Range
lastrow = Cells(Rows.Count, "B").End(xlUp).row
Set datarng = Range ("b2:b" & lastrow)

Hi.

This should work ok for you. It will delete all rows within a
selected range if the cell contains a date:-

Sub DeleteNotDates()

Dim rngCell As Range

For Each rngCell In Selection

If IsDate(rngCell.Value) Then
Rows(rngCell.Row & ":" & rngCell.Row).Select
Selection.Delete Shift:=xlUp
End If
Next

End Sub

Hope this helps,
Matt Richardson
http://teachr.blogspot.com
 

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

Top