Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Exclude date

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Exclude date

try using or instead of and

"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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Exclude date

Hi dmoney,

This doesn't work either.

"dmoney" wrote:

try using or instead of and

"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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Exclude date

You are using an unusual date format dd/mm/yyyy not the usual mm/dd/yyyy.

On your worksheet "Ruwe data",
select the Column G & H,
format cell - cateory: custom
& enter "dd/mm/yyyy" in the Type box.

Hope that helps.

J Knowles

"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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Exclude date

Hi DataHog,

This 2 doesn't change the problem.

"DataHog" wrote:

You are using an unusual date format dd/mm/yyyy not the usual mm/dd/yyyy.

On your worksheet "Ruwe data",
select the Column G & H,
format cell - cateory: custom
& enter "dd/mm/yyyy" in the Type box.

Hope that helps.

J Knowles

"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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Exclude date

Be sure you change the format for the whole columns (G & H) to custom -
dd/mm/yyyy.

To test, go to the bottom of your data in column G and enter a test date
26/02/2009, then select the auto fill feature (the lower right corner of the
cell - click and drag down) and drag down 10 or so cells, does it continue
with 27/02/2009, 28/02/2009, 01/03/2008, 02/03/2008 ..... If it does, you
got the format set correctly.

This code below works for me.

Sub CommandButton7_Click()
' highlight Col G & H, Format Cell - Custom - dd/mm/yyyy
Dim lngLastRow As Long
Dim i As Long
Dim Reeks1 As Variant
Dim Reeks2 As Variant
Reeks1 = InputBox("Start Date dd/mm/yyyy")
If Reeks1 = False Then Exit Sub
Reeks2 = InputBox("End Date dd/mm/yyyy")
If Reeks2 = False Then Exit Sub

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


"Basta1980" wrote:

Hi DataHog,

This 2 doesn't change the problem.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Exclude date

Okay the other routine bombed - this really works this time.

I have just learned when using dimension as Date it must be mm/dd/yyyy format.

So I changed my code to:
Dim Reeks1 As Date
Dim Reeks2 As Date
and
If Format(Cells(i, "G"), "mm/dd/yyyy") = Reeks1 And _
Format(Cells(i, "H"), "mm/dd/yyyy") < Reeks2 Then


So you must use format cells - standard date format mm/dd/yyyy on Column G & H

And this code will work.

Sub CommandButton7_Click()
Dim lngLastRow As Long
Dim i As Long
Dim Reeks1 As Date
Dim Reeks2 As Date
Reeks1 = Application.InputBox("Start Date", Default:=Range("G2").Value,
Type:=9)
If Reeks1 = False Then Exit Sub
Reeks2 = Application.InputBox("End Date",
Default:=Range("H1").End(xlDown).Value, Type:=9)
If Reeks2 = False Then Exit Sub
lngLastRow = Sheets("Sheet1").Cells(Rows.Count, "G").End(xlUp).Row

For i = lngLastRow To 2 Step -1
If Format(Cells(i, "G"), "mm/dd/yyyy") = Reeks1 And _
Format(Cells(i, "H"), "mm/dd/yyyy") < Reeks2 Then
Else
Rows(i).EntireRow.Delete Shift:=xlUp
End If
Next i

End Sub


"Basta1980" wrote:

Hi DataHog,

This 2 doesn't change the problem.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Exclude date

You are here comparing strings and not dates and that is the reason of the
wrong behavior.

Take two dates that I can show in your format (dd/mm/yyyy);

20/06/2008
and
15/07/2008

if you compare them as strings then the first is greater than the other :D

So the solution would be or to use a format whit which the operators < and
function well (normally this is the standard ISO format: YYYYMMDD) or to
conver the user input to a date value and compare the dates as dates not as
string.

Best regards,
Leo


"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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date count to exclude weekends Colin Hayes Excel Worksheet Functions 0 January 20th 09 01:24 AM
Add days to a date, but exclude holidays Chickadee Excel Worksheet Functions 13 July 31st 08 04:22 PM
How do I Exclude a list of dates in a date calculation? Ryan Excel Worksheet Functions 2 June 11th 08 12:29 AM
Date Calculation to exclude weekends Vim Excel Worksheet Functions 2 January 24th 06 02:58 PM
Date exclude weekdays LukePW New Users to Excel 9 December 20th 04 05:00 PM


All times are GMT +1. The time now is 11:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"