Exclude date
Untested, but it did compile:
Option Explicit
Private Sub CommandButton7_Click()
Dim lngLastRow As Long
Dim i As Long
Dim Reeks1 As Variant
Dim Reeks2 As Variant
Reeks1 = InputBox("Start")
If IsDate(Reeks1) Then
Reeks1 = CDate(Reeks1)
Else
MsgBox "Please try again and enter a date!"
Exit Sub
End If
Reeks2 = InputBox("End")
If IsDate(Reeks2) Then
Reeks1 = CDate(Reeks2)
Else
MsgBox "Please try again and enter a date!"
Exit Sub
End If
With Sheets("Ruwe data")
lngLastRow = .Cells(.Rows.Count, "G").End(xlUp).Row
For i = lngLastRow To 2 Step -1
If .Cells(i, "G").Value = Reeks1 _
And .Cells(i, "H").Value < Reeks2 Then
Else
.Rows(i).Delete
End If
Next i
End With
End Sub
If you really wanted to compare those formatted strings, I would think that
you'd want to format each value and use yyyymmdd as the format.
Basta1980 wrote:
Hi,
I have a sheet containing dates in column G and H. I want Excel to delete
the rows where data is matched from an inputbox and the data in column G and
H and doesn't qualify. I have a code (see below) that i got from an earlier
post, thing is that when I use the code it deletes all rows.
So if for instance if I need all rows to be deleted where the date in column
G is earlier than Reeks1 (i.e. 01/07/2007) and the date in Column H is later
than Reeks 2 (i.e. 30/06/2008), the code below deletes everything although I
have manualy checked the list and there is at least one row which meets the
specific criterai and therefore should not be deleted. I Checked the format
cells, even text to columns. But what am I doing wrong?
Private Sub CommandButton7_Click()
Dim lngLastRow As Long
Dim i As Long
Reeks1 = InputBox("Start")
Reeks2 = InputBox("Eind")
lngLastRow = Sheets("Ruwe data").Cells(Rows.Count, "G").End(xlUp).Row
For i = lngLastRow To 2 Step -1
If Format(Cells(i, "G"), "dd/mm/yyyy") = Reeks1 And _
Format(Cells(i, "H"), "dd/mm/yyyy") < Reeks2 Then
Else
Rows(i).EntireRow.Delete Shift:=xlUp
End If
Next i
End Sub
--
Dave Peterson
|