Read time formatted cell in VBA

VBA-Noob

New Member
Joined
Dec 17, 2012
Messages
13
Hi,
I have an big problem! When I want to read the time from an time formatted cell it instead of 07:45:00 it Excel reads it as 0,322.....

This is the script I use:

If Range("Z1") > "" Then
...............
..............
..............
.............

I'm greateful for all help I can got!

Thanks!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Times in Excel are just numbers formatted in a special way. 24 hours equals 1. So 07:45 = 0.322.
 
Upvote 0
As VoG implied, the decimal is just a fraction of a day. If you want that number formatted as time try (if time is in A1):
Code:
debug.print format(range("A1"),"hh:mm:ss")
 
Upvote 0
As VoG implied, the decimal is just a fraction of a day. If you want that number formatted as time try (if time is in A1):
Code:
debug.print format(range("A1"),"hh:mm:ss")

Hi,

Thank you so much, but where schould I place this function? Inside the If-statement och before?

Sorry but Im newbegginner.
 
Upvote 0
That simply shows the time value as a time which was your initial request. You need to supply more information about what you are trying to achieve. You mention an If statement but what is the criteria? If you are comparing against a time, say 12pm, then you could use
Rich (BB code):
If Range("Z1") > 0.5 then '12/24 =0.5 
...
End  If
 
Upvote 0
That simply shows the time value as a time which was your initial request. You need to supply more information about what you are trying to achieve. You mention an If statement but what is the criteria? If you are comparing against a time, say 12pm, then you could use
Rich (BB code):
If Range("Z1") > 0.5 then '12/24 =0.5 
...
End  If

Thank you man. Does it matters If I use european time, like 23:00:00
 
Upvote 0
Excel just considers that to be 23/24=0.95833 formatted in a specific way. No matter what format the time is displayed in (23:00:00, 11:00:00pm etc.) there is no difference to the underlying number.
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,517
Members
449,088
Latest member
RandomExceller01

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