Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
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
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
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
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
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
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
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
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro to delete rows based on a condition | Excel Worksheet Functions | |||
How do you format an auto update to delete rows with expired date | Excel Worksheet Functions | |||
Is there a way to delete a cell value based on a condition? | Excel Discussion (Misc queries) | |||
Can I delete an entire row if condition is not met? | Excel Worksheet Functions | |||
how do I delete all rows that match a condition? | Excel Worksheet Functions |