Adding time in HH:SS format.

USAMax

Well-known Member
Joined
May 31, 2006
Messages
846
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet that has time listed in hours and minutes.

I need to add these times together but every now and then I get a, "Type Mismatch" error. Here is what the code looks like.

code
Public IndexArray(12, 3) As Double
Public Lvl3Sum As Date

x=3
Format(IndexArray(3, 2), "hh:mm") = Cells(x,3)
Lvl3Sum = Format(Lvl3Sum, "hh:mm") + Format(IndexArray(3, 2), "hh:mm")
code

The code is too long to list but you can see the array type is Double and Lvl3Sum is Date. I am not using a date but I thought this was the best type to use.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
how can you have a function call to format on the left side of the equals?
 
Upvote 0
Lvl3Sum is a variable that has been declared as a Date type.
 
Upvote 0
the line above that says:
Format(IndexArray(3, 2), "hh:mm") = Cells(x,3)

which has the format on the left of the equals
 
Upvote 0
I am not sure what you are trying to do. Times are just decimal numbers formatted to look like a time. Even if Excel is displaying hh:mm it is still a decimal number and just be added. FORMAT is useful for converting it to a string to display as part of a longer string

timeMsg="the time is " & Format(now(),"hh:mm")
 
Upvote 0
I am not sure what you are trying to do. Times are just decimal numbers formatted to look like a time. Even if Excel is displaying hh:mm it is still a decimal number and just be added. FORMAT is useful for converting it to a string to display as part of a longer string

timeMsg="the time is " & Format(now(),"hh:mm")

The problem is that I am using this variable to verify that the calculations are correct as I step through the program. Just from looking at the decimal numbers I cannot tell if it is adding together correctly but it is easy to see 00:10 and 00:15 should be 00:25 but if they are decimal I can tell if the two numbers added together correctly but that is all I can tell.

I need to see the value as a time to test the program.
 
Upvote 0
dim newTime as string
newTime = format(Lvl3Sum+cells(x,3),"hh:mm")
Lvl3Sum = Lvl3Sum+cells(x,3)
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top