View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
bst bst is offline
external usenet poster
 
Posts: 19
Default performing calculations on time data

T Lavedas wrote in
:


That might explain the problem you are having (or will have) in
testing against <30 or more than 30 minutes. There are two internal
VBA functions you probably want to understand: TimeValue() and
DiffDate() in order to perform this comparison. They might also apply
to your problem in subtracting the numbers in version 2000 (if it
doesn't perform the time conversion automatically, as appears to be
the case from the type mismatch problem). In that case, you might
need to use something like ...

Sub test()
With ActiveWorkbook.Sheets(1)
.Cells(2, 3).Value = TimeValue(.Cells(2, 2).Value) -
TimeValue(.Cells(2, 1).Value)
.Cells(2, 3).NumberFormat = "hh:mm"
End With
End Sub

HTH,

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/


the timevalue function works great. i am ashamed that i did not find it
on my own. you would think that would show up somehwhere in the google
search. i did search the object browser but of course i forgot to simply
search help. i think it is the second function listed.

you were a great help.

thanks
bst