ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Time Calculation (https://www.excelbanter.com/excel-programming/338740-time-calculation.html)

HeartSA

Time Calculation
 
Getting a type mismatch error.

I have a cell (A1) with a custom format of mm:ss
I have a macro that is run that should add :10 seconds to the time, but I am
getting a type mimatch error. Not sure why.
Range("A1").value = Range("A1").value + time(0,0,10)

Please advise.

Thanks,
Doug



Tom Ogilvy

Time Calculation
 
In VBA it is TimeSerial:
Range("A1").value = Range("A1").value + timeserial(0,0,10)

--
Regards,
Tom Ogilvy



"HeartSA" wrote in message
...
Getting a type mismatch error.

I have a cell (A1) with a custom format of mm:ss
I have a macro that is run that should add :10 seconds to the time, but I

am
getting a type mimatch error. Not sure why.
Range("A1").value = Range("A1").value + time(0,0,10)

Please advise.

Thanks,
Doug





George Nicholson[_2_]

Time Calculation
 
Probably because the VBA Time function isn't the same as the Excel Worksheet
function of the same name. Use DateAdd

Range("A1") = DateAdd("s",10, Range("A1"))
or
Range("A1") = Range("A1") + TimeSerial(0, 0, 10)


If that doesn't work then maybe A1 is text rather than numeric:
Range("A1") = DateAdd("s",10, DateValue(Range("A1")))

HTH,

--
George Nicholson

Remove 'Junk' from return address.


"HeartSA" wrote in message
...
Getting a type mismatch error.

I have a cell (A1) with a custom format of mm:ss
I have a macro that is run that should add :10 seconds to the time, but I
am
getting a type mimatch error. Not sure why.
Range("A1").value = Range("A1").value + time(0,0,10)

Please advise.

Thanks,
Doug





HeartSA

Time Calculation
 
Thank you both, that did the trick.


"Tom Ogilvy" wrote in message
...
In VBA it is TimeSerial:
Range("A1").value = Range("A1").value + timeserial(0,0,10)

--
Regards,
Tom Ogilvy



"HeartSA" wrote in message
...
Getting a type mismatch error.

I have a cell (A1) with a custom format of mm:ss
I have a macro that is run that should add :10 seconds to the time, but

I
am
getting a type mimatch error. Not sure why.
Range("A1").value = Range("A1").value + time(0,0,10)

Please advise.

Thanks,
Doug








All times are GMT +1. The time now is 02:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com