0,5 time format is 00:00 and not 12:00

Acroach

New Member
Joined
Jun 9, 2010
Messages
4
Hi Guys,

I came across a weird thing in VBA for Excel:

For our planning department I designed a sheet so that the expected delivery times automatically get uploaded to our database. The times get rounded down to the nearest half our and than I add two hours and generate a string to upload in the database. All works fine except for times between: 12:00 and 12:29 in the code below info2 becomes the value "0,5" (or half day/ 12:00)

Code:
info3 = ActiveCell.Value
info2 = Application.WorksheetFunction.Floor(info3, 1 / (24 * 2))
info1 = info2 + 0.08333333333
info4 = "Verwachte lostijd tussen " & Format(info2, "hh:mm") & " en " & Format(info1, "hh:mm") & " SJAB "
The code above should come back with
"Verwachte lostijd tussen 12:00 en 14:00 SJAB"

but instead it gives me
"Verwachte lostijd tussen 00:00 en 14:00 SJAB"

I assume it has something to do with the formatting but i'm not quite sure.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Instead of "hh:mm", enter "hh:mm am/pm" in both places
 
Upvote 0
Thanks for your answer, but...

then I will get the AM/PM format while we prefer to use the 24h format.
 
Upvote 0
What is time format in ActiveCell.Value?
 
Upvote 0
I managed to reproduce your problem once, but now I get:

Verwachte lostijd tussen 12:00 en 14:00 SJAB

How have you declared your variables?
 
Upvote 0
I too get the result as "Verwachte lostijd tussen 12:00 en 14:00 SJAB" when my activecell value =12:01 as Andrew.
 
Upvote 0
Ahhh.. that's it!

I declared all the info's as Strings, Now i've changed info2 and info3 to variants and it all works smooth!

Thank you very much for your help!

Kind regards from Holland!
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

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