Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 131
Default Delete rows with date more than 48 hours with a condition..

In the below table I want to delete rows with dates more that 48 hours in
column K if column J="ABC"

Column J|Column K
ABC 29-01-09
ABC 30-01-09
ABC 30-01-09
MNO 31-01-09
MNO 31-01-09
ABC 03-02-09
MNO 03-02-09
MNO 31-01-09
MNO 01-02-09
ABC 04-02-09


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default Delete rows with date more than 48 hours with a condition..

48 hours is two days. Try this macro:

Sub rowkiller()
Dim n As Long
Dim d As Date
Dim lt As String
Dim dte As Date
d = Date
n = Cells(Rows.Count, "J").End(xlUp).Row
For i = n To 1 Step -1
lt = Cells(i, "J").Value
dte = Cells(i, "K").Value
If lt = "ABC" And d - dte 2 Then
Rows(i).Delete
End If
Next
End Sub

The result on your posted data is:

MNO 31-01-09
MNO 31-01-09
ABC 03-02-09
MNO 03-02-09
MNO 31-01-09
MNO 01-02-09
ABC 04-02-09


--
Gary''s Student - gsnu200831


"Kashyap" wrote:

In the below table I want to delete rows with dates more that 48 hours in
column K if column J="ABC"

Column J|Column K
ABC 29-01-09
ABC 30-01-09
ABC 30-01-09
MNO 31-01-09
MNO 31-01-09
ABC 03-02-09
MNO 03-02-09
MNO 31-01-09
MNO 01-02-09
ABC 04-02-09


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 131
Default Delete rows with date more than 48 hours with a condition..

Hi, I tried this, but there is an error in ' dte = Cells(i, "K").Value



"Gary''s Student" wrote:

48 hours is two days. Try this macro:

Sub rowkiller()
Dim n As Long
Dim d As Date
Dim lt As String
Dim dte As Date
d = Date
n = Cells(Rows.Count, "J").End(xlUp).Row
For i = n To 1 Step -1
lt = Cells(i, "J").Value
dte = Cells(i, "K").Value
If lt = "ABC" And d - dte 2 Then
Rows(i).Delete
End If
Next
End Sub

The result on your posted data is:

MNO 31-01-09
MNO 31-01-09
ABC 03-02-09
MNO 03-02-09
MNO 31-01-09
MNO 01-02-09
ABC 04-02-09


--
Gary''s Student - gsnu200831


"Kashyap" wrote:

In the below table I want to delete rows with dates more that 48 hours in
column K if column J="ABC"

Column J|Column K
ABC 29-01-09
ABC 30-01-09
ABC 30-01-09
MNO 31-01-09
MNO 31-01-09
ABC 03-02-09
MNO 03-02-09
MNO 31-01-09
MNO 01-02-09
ABC 04-02-09


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Delete rows with date more than 48 hours with a condition..

What's in that cell?



Kashyap wrote:

Hi, I tried this, but there is an error in ' dte = Cells(i, "K").Value

"Gary''s Student" wrote:

48 hours is two days. Try this macro:

Sub rowkiller()
Dim n As Long
Dim d As Date
Dim lt As String
Dim dte As Date
d = Date
n = Cells(Rows.Count, "J").End(xlUp).Row
For i = n To 1 Step -1
lt = Cells(i, "J").Value
dte = Cells(i, "K").Value
If lt = "ABC" And d - dte 2 Then
Rows(i).Delete
End If
Next
End Sub

The result on your posted data is:

MNO 31-01-09
MNO 31-01-09
ABC 03-02-09
MNO 03-02-09
MNO 31-01-09
MNO 01-02-09
ABC 04-02-09


--
Gary''s Student - gsnu200831


"Kashyap" wrote:

In the below table I want to delete rows with dates more that 48 hours in
column K if column J="ABC"

Column J|Column K
ABC 29-01-09
ABC 30-01-09
ABC 30-01-09
MNO 31-01-09
MNO 31-01-09
ABC 03-02-09
MNO 03-02-09
MNO 31-01-09
MNO 01-02-09
ABC 04-02-09



--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 131
Default Delete rows with date more than 48 hours with a condition..

I have dates in cloumn K and some names in column J.

I want to delete the rows in which date is within 48 hrs and name is ABC only.

date format is '02-02-2009 13:27:00'



"Dave Peterson" wrote:

What's in that cell?



Kashyap wrote:

Hi, I tried this, but there is an error in ' dte = Cells(i, "K").Value

"Gary''s Student" wrote:

48 hours is two days. Try this macro:

Sub rowkiller()
Dim n As Long
Dim d As Date
Dim lt As String
Dim dte As Date
d = Date
n = Cells(Rows.Count, "J").End(xlUp).Row
For i = n To 1 Step -1
lt = Cells(i, "J").Value
dte = Cells(i, "K").Value
If lt = "ABC" And d - dte 2 Then
Rows(i).Delete
End If
Next
End Sub

The result on your posted data is:

MNO 31-01-09
MNO 31-01-09
ABC 03-02-09
MNO 03-02-09
MNO 31-01-09
MNO 01-02-09
ABC 04-02-09


--
Gary''s Student - gsnu200831


"Kashyap" wrote:

In the below table I want to delete rows with dates more that 48 hours in
column K if column J="ABC"

Column J|Column K
ABC 29-01-09
ABC 30-01-09
ABC 30-01-09
MNO 31-01-09
MNO 31-01-09
ABC 03-02-09
MNO 03-02-09
MNO 31-01-09
MNO 01-02-09
ABC 04-02-09



--

Dave Peterson

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
Macro to delete rows based on a condition Darrilyn Excel Worksheet Functions 1 September 6th 07 12:12 AM
How do you format an auto update to delete rows with expired date Rneedshelp Excel Worksheet Functions 0 May 29th 07 04:30 PM
Is there a way to delete a cell value based on a condition? Peanut Excel Discussion (Misc queries) 2 October 2nd 06 09:55 PM
Can I delete an entire row if condition is not met? Christine Excel Worksheet Functions 8 May 4th 06 09:47 AM
how do I delete all rows that match a condition? djhs63 Excel Worksheet Functions 5 March 16th 05 03:55 PM


All times are GMT +1. The time now is 07:42 AM.

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

About Us

"It's about Microsoft Excel"