Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default compare 2 dates and give the date conditions are met


I run a macro that basically compares the time beetween two dates and if
two conditions are met, colors the backgorund either Yellow or Red.
the code inserts a column and pastes the time difference on it then it
colors the background, the time difference is given in Decimal, I would
like to change the code so that when the conditions are met it gives the
date when the condition was met.
For example it requires to compare a ticket that was created on
06/02/2006 14:07 and if between 96 hours to 120 hours have passed then
color yellow, or if more than 120 hours have passed then color Red, the
change I would like to make is that instead of giving the total time
passed since creation to system date in decimal, it gives the date and
time when the 96 or 120 hours happened, in this case the 120 hours
would have fallen sometime on 10/02/2006, that is the date I would like
to see pasted and background colored. The code uses networkdays so that
only weekdays are included for Medium and High, Top does include
weekends 24/7.
The code uses Column E looking for keywords Medium, High and Top, uses
column H which is date created and inserts column I, where the time is
pasted and colored.
Any help will be much appreciated.

Below is the code used:


Code:
--------------------
Dim ws1 As Worksheet
Dim r As Long, lastrow As Long

Set ws1 = Worksheets("Currently Open Report")
With ws1

Columns("I").Insert Shift:=xlToRight
.Cells(1, "I") = "Deadline SLA"
Columns("I").NumberFormat = "###0.00"

lastrow = .Cells(Rows.Count, "E").End(xlUp).Row

dt2 = CDec(Now())

For r = 2 To lastrow

dt1 = CDec(.Cells(r, "H"))

Select Case UCase(.Cells(r, "E"))

Case Is = "MEDIUM"
TimeDiff = (networkdays(dt1, dt2) + ((dt2 - Int(dt2)) - (dt1 - Int(dt1)))) * 24
.Cells(r, "I") = TimeDiff

If TimeDiff 96 And TimeDiff <= 120 Then
.Cells(r, "I").Interior.ColorIndex = 6
End If

If TimeDiff 120 Then
.Cells(r, "I").Interior.ColorIndex = 3
End If

Case Is = "HIGH"
TimeDiff = (networkdays(dt1, dt2) + ((dt2 - Int(dt2)) - (dt1 - Int(dt1)))) * 24
.Cells(r, "I") = TimeDiff

If TimeDiff 60 And TimeDiff <= 72 Then
.Cells(r, "I").Interior.ColorIndex = 6
End If

If TimeDiff 72 Then
.Cells(r, "I").Interior.ColorIndex = 3
End If

Case Is = "TOP"
TimeDiff = (dt2 - dt1) * 24
.Cells(r, "I") = TimeDiff
If TimeDiff 3 And TimeDiff <= 4 Then
.Cells(r, "I").Interior.ColorIndex = 6
End If
If TimeDiff 4 Then
.Cells(r, "I").Interior.ColorIndex = 3
End If
End Select
Next r

End With

End Sub
Code:
--------------------


--
chin_un_len
------------------------------------------------------------------------
chin_un_len's Profile: http://www.excelforum.com/member.php...o&userid=30914
View this thread: http://www.excelforum.com/showthread...hreadid=512012

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
Compare multiple dates, can enumerate cell based on most recent date Brian Excel Worksheet Functions 7 May 9th 06 11:02 PM
Compare date against multiple dates Struggling Excel Discussion (Misc queries) 1 April 26th 06 03:19 PM
Compare date of a transaction against a range of dates D Campbell Excel Worksheet Functions 1 August 7th 05 09:40 PM
Compare dates (one cell not in date format) craigcsb Excel Discussion (Misc queries) 5 June 28th 05 05:07 PM
Compare current date to 2 dates Terri Excel Programming 1 October 21st 04 03:55 PM


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