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

Hi,

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'

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.programming
external usenet poster
 
Posts: 12
Default Delete rows with date more than 48 hours with a condition..

Here is one solution.

Public Sub Test()
Dim rng As Range
Dim cel As Range
Dim iCounter As Integer
Dim iLastRow As Integer
Dim dtToday As Date
Dim dtCellDate As Date

Set rng = Range("J1:J100") 'Change the J-rows as appropriate
iLastRow = rng.Cells.Count
For iCounter = iLastRow To 1 Step -1 'Workup from the bottom!
With rng
If .Cells(iCounter).Value = "ABC" Then
dtToday = Date 'Today's date
dtCellDate = .Cells(iCounter).Offset(0, 1).Value 'Date
value in K cell.
If dtToday - dtCellDate = 2 Then
.Cells(iCounter).EntireRow.Delete
End If
End If

End With
Next
End Sub

Paul



"Kashyap" wrote in message
...
Hi,

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'

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.programming
external usenet poster
 
Posts: 131
Default Delete rows with date more than 48 hours with a condition..

Hey, its working perfect.. Thanks Paul

"Paul Wilson" wrote:

Here is one solution.

Public Sub Test()
Dim rng As Range
Dim cel As Range
Dim iCounter As Integer
Dim iLastRow As Integer
Dim dtToday As Date
Dim dtCellDate As Date

Set rng = Range("J1:J100") 'Change the J-rows as appropriate
iLastRow = rng.Cells.Count
For iCounter = iLastRow To 1 Step -1 'Workup from the bottom!
With rng
If .Cells(iCounter).Value = "ABC" Then
dtToday = Date 'Today's date
dtCellDate = .Cells(iCounter).Offset(0, 1).Value 'Date
value in K cell.
If dtToday - dtCellDate = 2 Then
.Cells(iCounter).EntireRow.Delete
End If
End If

End With
Next
End Sub

Paul



"Kashyap" wrote in message
...
Hi,

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'

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




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
Delete rows with date more than 48 hours with a condition.. Kashyap Excel Worksheet Functions 4 February 5th 09 03:51 AM
Delete rows based on more than one condition. thomas Excel Programming 3 September 24th 08 02:20 PM
macro to delete rows on condition Todd Excel Programming 1 August 24th 06 11:44 PM
Delete Rows - adding a second condition TP[_3_] Excel Programming 6 May 13th 04 08:44 AM
delete rows with certain condition Grey Excel Programming 2 December 19th 03 12:05 PM


All times are GMT +1. The time now is 12:27 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"