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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to display time on userform textbox 1

Status
Not open for further replies.

adamstuff

Technical User
Sep 13, 2005
41
0
0
US
Hi all,
I have a text box on a userform that I’m trying to use for both display of a cell from the sheet and as an input back to the cell. The problem is that the cell formatted as Time (13:30). I’ve tried different formats with same results. The textbox displays the TimeSerial instead of the time in the cell.
I initialize the userform by reading the cell (StartTime) and converting with Hour() and Minute() functions. The textbox displays properly except for one minor flaw. If the minutes end in a zero, it only displays one digit. Eg cell has 8:20, textbox shows 8:1.
If VBA had a Time format it would be nice, but what that does is the same as Now(). That is not what I want. I have several other cells on the sheet that have to have times put on them and I’m going to have the same problem. These times are start and finish time that a user puts in as a basis for a project time tracker. These are not running clock times, just times. I use these entries for time calculations all over the sheet, so I just can’t put a text format out there.
I have found tons of stuff for manipulating dates, but very, very little about time on sheets and in VBA. Is there a way to display time and entry properly in a userform textbox?Can anyone help, please. I hate being stymied just because Micosoft’s conversion doesn’t act as advetised.
TIA


Heisenberg was probably right.
 



Hi,

Check out the Format function...
Code:
MyTextbox.text = format([MyTimeValue],"hh:nn:ss")


Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Thanks Skip. [thumbsup] Here's your star. How did you find this, or how did you figure it out? I hate not having a VB or VBA Syntax Syllabus. I searched on every combination of excel, vba, vb, textbox, time, date and couldn't find much. I used to consider myself a good searcher, but I bow befor the Master.
Thanks again!

Heisenberg was probably right.
 
The F2 key (Object Browser) is a good friend for searcher ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks to you too, PH. Just one question to you from apparently a BAD searcher. [glasses] I can't find anything like Skip's answer in the Object Browser either. Guess I just ain't worth a durn.

Heisenberg was probably right.
 
In the class column select Strings ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top