View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
John Schneider John Schneider is offline
external usenet poster
 
Posts: 9
Default Time Difference in VBA Macro

One more thing I can't figure out. The user inputs a start time, end time,
and how long for lunch. Something is wrong with the way I'm trying to
calculate this. The start and end times are absolute times (i.e. 8:30 am and
5:30 pm), but I need the "how long for lunch" to be just the number of
minutes, i.e. 45, 60, etc. How do I get this to work?

Here's my code:

Dim startTime As Date
Dim endTime As Date
Dim Lunch As Date
Dim totHours As Date

startTime = Application.InputBox("Enter Start Time", "Calculate Hours", , ,
, , , 1)
endTime = Application.InputBox("Enter End Time", "Calculate Hours", , , , ,
, 1)
Lunch = Application.InputBox("How Long For Lunch?", "Calculate Hours", , , ,
, , 1)

totHours = ((endTime - startTime) * 24) - (Lunch * 24)

ActiveCell.Value = totHours
ActiveCell.NumberFormat = "#0.0"


"Billy Liddel" wrote:

John

Excel calculates dates as numbers, normally counting from 1/1/1900. Time is
calculated as fractions of a day. so 9:00 is 9/24 of a day. Bear this in mind
when making any calculations with time.

Peter