Remove rows with dates

E

ExcelBeginner

I tried this macro and it doesn't seem to do anything .. .I found it below.
I was hoping it would delete row with certain dates in a spreadsheet. Is
there something missing in the code?

Sub test1()
Dim c As Excel.Range
x = InputBox("start date?")
y = InputBox("stop date?")
For Each c In Selection
If c < x And c > y Then
cell.EntireRow.delete
End If
Next
End Sub
 
R

Rob van Gelder

Looks broken to me...

If you want the code to delete dates in the Selection which are outside the
date window specified, then change the following:
from: If c < x And c > y Then
to: If c < x Or c > y Then

If you want the code to delete dates in the Selection which are inside the
date window specified, then change the following:
from: If c < x And c > y Then
to: If c >= x And c <= y Then


Just beware of the < > <= >= because they can cause pain with dates
(especially date windows) if you don't get the rules for them correct up
front - they can be very different depending on purpose.
 

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