Macro to delete any rows in column ‘A’ which do not have a date in them

robertguy

Board Regular
Joined
May 1, 2008
Messages
121
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Hi.

Can any please advise me of the macro code I need to check all cells in column ‘A’ for any cells that do not contain a date and then delete them N.B. the dates (to keep) will be in the format dd/mm/yy

Any help would be greatly appreciated

Many thanks in advance


Rob

N.B Excel version 2003 and I have asked this question in another forum i.e.
http://www.excelforum.com/excel-general/791108-macro-to-delete-any-rows-in-column-a-which-do-not-have-a-date-in-them.html which as yet has not been answered.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try this - I assumed that you wanted the cells deleted not just blanked

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    With Range("A" & i)
        If Not IsDate(.Value) Then .Delete shift:=xlShiftUp
    End With
Next i
End Sub
 
Upvote 0
Vog,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
many thanks for your prompt reply it is very much appreciated...that said I think I messed up my criteria in that the macro should identify any cells in column 'A' that does not have a date in e.g. dd/mm/yy or is blank then delete the entire corresponding row ensuring the rows move up so that are continuous.<o:p></o:p>
<o:p> </o:p><o:p> </o:p>
Any thought on how to amend your macro code ??<o:p></o:p>
<o:p> </o:p> <o:p></o:p>
regards<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p> <o:p></o:p>
Rob<o:p></o:p>
 
Last edited:
Upvote 0
Try

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    With Range("A" & i)
        If Not IsDate(.Value) Then .EntireRow.Delete
    End With
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,530
Messages
6,179,373
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top