FruitUser
FruitUser

Reputation: 115

Add minutes to a time (hh:mm) in excel vba

I am making a production schedule, and would like to add ex. 78 minutes to a time ex. 7:05 (am) in VBA. How would I go about doing this? This is what I have tried so far, but I'm getting an error 13 type:mismatch

Dim TUntilPump As Integer
Dim TFPump As Long, TStartPump As Long

TUP = 78
TFP = Time(0, TUP, 0)
TSP = Time(7,05,0) + TFP

I'm thinking it has something to do with my variable dimensions or the format of my times, but I have no idea what I'm doing wrong. Any help is appreciated, and thanks in advance!

Upvotes: 9

Views: 37280

Answers (2)

user4039065
user4039065

Reputation:

Times should be considered double type vars for this. Time is a decimal portion of a day (1). 0.5 is noon and 0.666666 is 04:00 pm. I've found that the TimeSerial function is good for constructing dates.

dim TFP as double, TSP as double, TUP as integer

TUP = 78
TFP = TimeSerial(0, TUP, 0)
TSP = TimeSerial(7, 5, 0) + TFP
'alternate
TSP = TimeSerial(7, 5 + TUP, 0)

Upvotes: 8

Scott Craner
Scott Craner

Reputation: 152450

use the DATEADD function:

TRP = dateadd("n",78,"7:05:00")

the "n" means minutes.

Upvotes: 22

Related Questions