Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Time from cells

Status
Not open for further replies.

JTBorton

Technical User
Jun 9, 2008
345
DE
I am recently posted a thread about some trouble I was having formatting cells on my spreadsheet to display time. The user enters the start time of a meeting on a form. The hour and minutes are placed in a text box in the format 11:00. Then they select radio buttons for AM/PM. The problem arose when I tried to put this information into the spreadsheet. Instead of displaying the time in h:mm AM/PM format it came out as a big, ugly, nasty decimal number. This problem was solved, with a little help from members of this forum, as follows:

.Cells(3, 4) = Trim(txtTime.Text) & IIf(optAM, " AM", " PM")
.Cells(3, 4).NumberFormat = "h:mm AM/PM"

Now the problem I have is reading the cells and converting the time back to the user form for editing. It will not read the time as a text string which I can then manipulate, but instead the big, hairy, nasty 0.458333333333333. It even cuts off my AM/PM when I read it in. How can I read the time into a variable in a way that I can extract the information that I want?
 
Hi JTBorton,

Hint:
Code:
Sub Test()
Dim Tm As Single
Tm = 0.458333333333333
MsgBox Format(Tm, "HH:mm AM/PM")
End Sub
Cheers

[MS MVP - Word]
 
See if you can make use of
Code:
? format(0.458333333333333,"h:nn AM/PM")
11:00 AM
 





Please read and understand...

faq68-5827.

The value that you posted can be FORMATTED (Not changed) as 11:00:00 AM. The VALUE is still 0.458333333333333.
Code:
YourRange.NumberFormat = "h:mm:ss AM/PM"


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
You may also consider the following:
Cells(3, 4).Text

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
All these answers worked great. Thanks alot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top