Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Michael Link
 
Posts: n/a
Default Date/Time Macro Puzzle

Hi, everyone--

Here is a macro that deposits the date and time into a cell, but which =
is=20
supposed to pop up a warning box when the time is after 5:00PM:

Sub NewDateAndTime()

Dim mPrompt As String
Dim mBoxStyle As Long
Dim mTitle As String
Dim mMsg As Variant

mPrompt =3D "It's after 5:00 PM! Click OK to enter time, but please =
remember=20
to enter TOTAL HOURS WORKED TONIGHT in the yellow box at right.=20
Thanks!"
mBoxStyle =3D 64
mTitle =3D "AFTER-HOURS ENTRY"

With ActiveCell

.Value =3D Now
.NumberFormat =3D "mm/dd/yy h:mm AM/PM"

If Now Mod 1 17 / 24 Then
mMsg =3D MsgBox(mPrompt, mBoxStyle, mTitle)
End If

End With

End Sub

The puzzle is this: in its current formulation, a warning box NEVER =
appears,=20
regardless of the time of day. However, if I reverse the sign in the=20
"If...Then" clause to <, a warning box ALWAYS appears, again regardless =
of=20
the time of day. (I have tried replacing the 17/24 designation with its=20
decimal equivalent [about 0.708333], but the same problem occurs.)

I have no idea what's going wrong. Any ideas how to get the warning to=20
appear only after 5:00 PM? I appreciate your help--this is driving me =
nuts!


  #2   Report Post  
Dave O
 
Posts: n/a
Default

There are probably a number of ways to skin this cat: one of them is to
use the Timer function, which returns the number of seconds elapsed
since midnight. In your case 5pm is 17 hours after midnight, which
equates to 17*60*60 or 61200 seconds. You could replace your code
If Now Mod 1 17 / 24 Then

.... with this:
If Timer = 61200 Then

This method will save you a lot of conversion of time strings to
numeric, etc.

Dave O

  #3   Report Post  
Michael Link
 
Posts: n/a
Default

I'll give it a shot! Unfortunately I need to go to a meeting, so it's =
going to be=20
a while before I can test this out, but at least I've got something to =
try when=20
I come back.
-----Original Message-----
There are probably a number of ways to skin this cat: one of them is to
use the Timer function, which returns the number of seconds elapsed
since midnight. In your case 5pm is 17 hours after midnight, which
equates to 17*60*60 or 61200 seconds. You could replace your code
If Now Mod 1 17 / 24 Then

.... with this:
If Timer =3D 61200 Then

This method will save you a lot of conversion of time strings to
numeric, etc.

Dave O

.

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
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Date/Time Macro Michael Link Excel Discussion (Misc queries) 6 February 15th 05 12:55 AM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM
Macro Formula revision? Mark Excel Worksheet Functions 1 November 28th 04 01:43 AM


All times are GMT +1. The time now is 04:28 PM.

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"