PC Review


Reply
Thread Tools Rate Thread

comparing times

 
 
bst
Guest
Posts: n/a
 
      2nd Jul 2008
i would like to flag certain cells based on the criteria below,
if the time in column A is between 5AM and 5PM and the word in column B is
False, i would like the cell in B marked red.
if the time in column A is between 5PM and 5AM and the word in column B is
True i would like the cell in B marked as red.

here is what i have so far:
If (sig = "TRUE" And shouldNotSigBool(time)) Then
.Cells(rowCtr, colSig).Interior.ColorIndex = 3 'after hours, no
sig needed
End If
If (sig = "FALSE" And shouldSigBool(time)) Then
.Cells(rowCtr, colSig).Interior.ColorIndex = 3 'normal hours,
sig needed
End If

and the functions:
Function shouldSigBool(time As Date) As Boolean
Const am As Date = #5:00:00 AM#
Const pm As Date = #5:00:00 PM#
If (time > am And time < pm) Then
shouldSigBool = True
Else
shouldSigBool = False
End If
End Function

Function shouldNotSigBool(time As Date) As Boolean
Const am As Date = #5:00:00 AM#
Const pm As Date = #5:00:00 PM#
If (time < am And time > pm) Then
shouldNotSigBool = True
Else
shouldNotSigBool = False
End If
End Function

from my sample data it looks as if the first conditional is completing,
however the second is not. can anyone spot a flaw in the logic? or is there
a beter way to do this?(i dont think an OR will work). unfortunatley i dont
know anyone else with any programming experience to bug with all my issues,
and it is terribly difficult to proofread my own work.

tia
bst
 
Reply With Quote
 
 
 
 
Charlie
Guest
Posts: n/a
 
      2nd Jul 2008
Change "And" to "Or" (and decide what to do if the time is EXACTLY 5am or
5pm, i.e. choose to use "<=", ">=" in one of your two functions. Look at
your logic carefully.)

Function shouldNotSigBool(time As Date) As Boolean
Const am As Date = #5:00:00 AM#
Const pm As Date = #5:00:00 PM#
If (time < am Or time > pm) Then
shouldNotSigBool = True
Else
shouldNotSigBool = False
End If
End Function



"bst" wrote:

> i would like to flag certain cells based on the criteria below,
> if the time in column A is between 5AM and 5PM and the word in column B is
> False, i would like the cell in B marked red.
> if the time in column A is between 5PM and 5AM and the word in column B is
> True i would like the cell in B marked as red.
>
> here is what i have so far:
> If (sig = "TRUE" And shouldNotSigBool(time)) Then
> .Cells(rowCtr, colSig).Interior.ColorIndex = 3 'after hours, no
> sig needed
> End If
> If (sig = "FALSE" And shouldSigBool(time)) Then
> .Cells(rowCtr, colSig).Interior.ColorIndex = 3 'normal hours,
> sig needed
> End If
>
> and the functions:
> Function shouldSigBool(time As Date) As Boolean
> Const am As Date = #5:00:00 AM#
> Const pm As Date = #5:00:00 PM#
> If (time > am And time < pm) Then
> shouldSigBool = True
> Else
> shouldSigBool = False
> End If
> End Function
>
> Function shouldNotSigBool(time As Date) As Boolean
> Const am As Date = #5:00:00 AM#
> Const pm As Date = #5:00:00 PM#
> If (time < am And time > pm) Then
> shouldNotSigBool = True
> Else
> shouldNotSigBool = False
> End If
> End Function
>
> from my sample data it looks as if the first conditional is completing,
> however the second is not. can anyone spot a flaw in the logic? or is there
> a beter way to do this?(i dont think an OR will work). unfortunatley i dont
> know anyone else with any programming experience to bug with all my issues,
> and it is terribly difficult to proofread my own work.
>
> tia
> bst
>

 
Reply With Quote
 
bst
Guest
Posts: n/a
 
      2nd Jul 2008
Doh! You are right. I don't know why i was fighting against using an OR
in my head.

thanks
bst

=?Utf-8?B?Q2hhcmxpZQ==?= <(E-Mail Removed)> wrote in
news:EBD61391-624A-40B9-A778-(E-Mail Removed):

> Change "And" to "Or" (and decide what to do if the time is EXACTLY 5am
> or 5pm, i.e. choose to use "<=", ">=" in one of your two functions.
> Look at your logic carefully.)
>
> Function shouldNotSigBool(time As Date) As Boolean
> Const am As Date = #5:00:00 AM#
> Const pm As Date = #5:00:00 PM#
> If (time < am Or time > pm) Then
> shouldNotSigBool = True
> Else
> shouldNotSigBool = False
> End If
> End Function
>
>
>
> "bst" wrote:
>
>> i would like to flag certain cells based on the criteria below,
>> if the time in column A is between 5AM and 5PM and the word in column
>> B is False, i would like the cell in B marked red.
>> if the time in column A is between 5PM and 5AM and the word in column
>> B is True i would like the cell in B marked as red.
>>
>> here is what i have so far:
>> If (sig = "TRUE" And shouldNotSigBool(time)) Then
>> .Cells(rowCtr, colSig).Interior.ColorIndex = 3 'after
>> hours, no
>> sig needed
>> End If
>> If (sig = "FALSE" And shouldSigBool(time)) Then
>> .Cells(rowCtr, colSig).Interior.ColorIndex = 3 'normal
>> hours,
>> sig needed
>> End If
>>
>> and the functions:
>> Function shouldSigBool(time As Date) As Boolean
>> Const am As Date = #5:00:00 AM#
>> Const pm As Date = #5:00:00 PM#
>> If (time > am And time < pm) Then
>> shouldSigBool = True
>> Else
>> shouldSigBool = False
>> End If
>> End Function
>>
>> Function shouldNotSigBool(time As Date) As Boolean
>> Const am As Date = #5:00:00 AM#
>> Const pm As Date = #5:00:00 PM#
>> If (time < am And time > pm) Then
>> shouldNotSigBool = True
>> Else
>> shouldNotSigBool = False
>> End If
>> End Function
>>
>> from my sample data it looks as if the first conditional is
>> completing, however the second is not. can anyone spot a flaw in the
>> logic? or is there a beter way to do this?(i dont think an OR will
>> work). unfortunatley i dont know anyone else with any programming
>> experience to bug with all my issues, and it is terribly difficult to
>> proofread my own work.
>>
>> tia
>> bst
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing Times in Text Boxes to Times in Cells Matt Microsoft Excel Programming 1 6th Aug 2006 04:10 AM
Comparing Times =?Utf-8?B?SnVzdCBMZWFybmluZw==?= Microsoft Excel Misc 4 19th Aug 2005 06:27 PM
Comparing Times trumpy81 Microsoft Excel New Users 3 29th Jun 2005 11:01 AM
Comparing times The Iconoclast Microsoft Access 1 8th Sep 2004 06:21 AM
Comparing two times (HH:MM:SS) CopperNic Microsoft Excel Programming 1 8th Jan 2004 08:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:15 AM.