Time format in code

  • Thread starter Thread starter K1KKKA
  • Start date Start date
K

K1KKKA

HYCH.
The code below works for what i want, BUT !!

In the worksheet "Lists" i want the 1st combobox to show the values as
hh:mm but am getting the display as decimal, where do i format the
code below to show "hh:mm"



Any help please!!


Private Sub UserForm_Initialize()
Dim cPart As Range
Dim ws As Worksheet
Set ws = Worksheets("Lists")
For Each cPart In ws.Range("A1:A12")
With Me.ComboBox1
.AddItem cPart.Value
.List(.ListCount - 1, 1) = cPart.Offset(0, 1).Value
End With
Next cPart
For Each cPart In ws.Range("B1:B7")
With Me.ComboBox2
.AddItem cPart.Value
.List(.ListCount - 1, 1) = cPart.Offset(0, 1).Value
End With
Next cPart
Me.ComboBox1.Value = ""
Me.ComboBox2.Value = ""
Me.ComboBox1.SetFocus
End Sub


Steve
 
If the cells are formatted correctly:
..List(.ListCount - 1, 1) = cPart.Offset(0, 1).Text

or apply the format you like:
..List(.ListCount - 1, 1) = format(cPart.Offset(0, 1).Value, "hh:mm")
 
If the cells are formatted correctly:
.List(.ListCount - 1, 1) = cPart.Offset(0, 1).Text

or apply the format you like:
.List(.ListCount - 1, 1) = format(cPart.Offset(0, 1).Value, "hh:mm")










--

Dave Peterson- Hide quoted text -

- Show quoted text -

Cheers Dave, sorted


Steve
 
Back
Top