Time format in code

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
 
D

Dave Peterson

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")
 
K

K1KKKA

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
 

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

Similar Threads

Number formats 1
VBA Coding Help for Beginner 0
Combobox number formats 4
Modifing example code 2
Userform list for more than one column of data 2
Deleting information 5
i need help!!!!! 0
Range query 5

Top