View Single Post
  #3   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

Its definately a work in progress, but here's what I have so far:

Sub testjs()

Dim startTime As String
Dim endTime As String
Dim totHours As String

startTime = Application.InputBox("Enter Start Time", "Calculate Hours", , ,
, , , 1)
endTime = Application.InputBox("Enter End Time", "Calculate Hours", , , , ,
, 1)

totHours = CDate(endTime) - CDate(startTime)

ActiveCell.Value = totHours

End Sub



"Bob Phillips" wrote:

Post up the code so we can see what you are doing.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"John Schneider" wrote in message
...
I'm trying to write a VBA macro to take the difference between two times
input by the user, calculate the difference, and put that value in the
cell.

The first input box prompts for the start time (i.e. 9:00AM) and the
second
prompts for the end time (i.e. 5:30PM). I've searched through this
newsgroup
and done Google searches, but something just isn't sinking in. I need the
value to come out as a decimal value. With the 9:00 - 5:30 example, the
cell
should show 8.5, but I keep getting -0.15. No doubt I'm missing something
obvious!

Thanks,
John