ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Time format for text box (https://www.excelbanter.com/excel-discussion-misc-queries/251074-time-format-text-box.html)

Hoyos

Time format for text box
 
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

Mike H

Time format for text box
 
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
"hoyos" wrote:

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


Mike

Time format for text box
 
Try this
TextBox78.Value = Format(Sheets("summary").Range("N21"), "hh:mm")
TextBox79.Value = Format(Sheets("summary").Range("N22"), "hh:mm")

"hoyos" wrote:

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


Hoyos

Time format for text box
 
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.

"Mike H" wrote:

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
"hoyos" wrote:

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


Hoyos

Time format for text box
 
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.


"Mike" wrote:

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

"hoyos" wrote:

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



All times are GMT +1. The time now is 12:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com