Time format for text box

H

hoyos

I'm struggling abit here. I have the following formatting code for a couple
of textboxes. But it's not working. Any suggestions?

Private Sub UserForm_Initialize()
TextBox78 = Format(Sheets("summary").Range("N21"), "hh:mm")
TextBox79 = Format(Sheets("summary").Range("N22"), "hh:mm")
End Sub
 
M

Mike H

Hi,

That works fine but you have to have the time displayed in N21 and not just
formatted to show the date.

You can change the format of N21 & N22 at runtime if necessary to make it
display the time

Sheets("summary").Range("N21") = _
Format(Sheets("summary").Range("N21"), "hh:mm")

then your line

TextBox78.Text = Format(Sheets("summary").Range("N21"), "hh:mm")

Mike
 
M

Mike

Try this
TextBox78.Value = Format(Sheets("summary").Range("N21"), "hh:mm")
TextBox79.Value = Format(Sheets("summary").Range("N22"), "hh:mm")
 
H

hoyos

Mike,
Thanks for replying. Do I put the first part of the formula in the sheet
code and the other in the textbox code?
Also the values in "hh:mm" are cumulative totals. It seems to go up to 24
hours and not beyond.
 
H

hoyos

Mike,
I have managed to sort it out by:

Code in sheet "summary":

Range("n21").Value = Range("m21").Value
Range("n22").Value = Range("m22").Value

Code in userform:

TextBox79.Text = Sheets("summary").Range("N21").Text
TextBox78.Text = Sheets("summary").Range("N22").Text

Many thanks for your interest.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top