View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones[_2_] Norman Jones[_2_] is offline
external usenet poster
 
Posts: 421
Default Time format in userform textbox

Hi Anon,

Try something like:

'=========
Option Explicit

Private Sub UserForm_Initialize()
Dim wb As Workbook
Dim SH As Worksheet
Dim Rng As Range
Dim i As Long

Set wb = ThisWorkbook
Set SH = wb.Sheets("Sheet1") '<<==== CHANGE
Set Rng = SH.Range("A1") '<<==== CHANGE

For i = 1 To 5
Me.Controls("Textbox" & i).Value = _
Rng.Offset(i - 1).Text
Next i

End Sub
'<<=========



---
Regards.
Norman
"anon" wrote in message
...
Hi all,

I thought this would be an easy solve but it has me baffled. I've read
quite a few old posts and still haven't a solution so would appreciate
any help.

I have a textbox on a userform I am trying to set to a time format.
(The textbox is bound to a ws cell and this is set to time format)

I have tried all of the below;

UserForm5.Controls("TextBox" & i).Text = Format$(ws.Range("g" & K),
"Short Time")
UserForm5.Controls("TextBox" & i).Text = Format$(ws.Range("g" & K),
"h:mm")
UserForm5.Controls("TextBox" & i).Text = Format$
(sheets("sheet4").range("g" & K), "H:mm")
UserForm5.Controls("TextBox" & i).Text = Format(ws.Range("g" & K),
"Short Time")
UserForm5.Controls("TextBox" & i).Text = Format(ws.Range("g" & K),
"h:mm")
UserForm5.Controls("TextBox" & i).Text =
Format(sheets("sheet4").range("g" & K), "H:mm")


None of which have worked - the time still shows as a decimal. I'd
appreciate any pointers as i'm baffled and getting very frustrated!