Help getting ComboBox to display time format

Deekappa

New Member
Joined
Nov 19, 2018
Messages
12
I have the code below in a userform, with 5 combo boxes. I need Combo Box 2 to display a time, but I can't get it to work. I've had a look around and tried a few suggestions, but can't seem to get it. Any suggestions would be hugely appreciated.

Code:
' Open UserForm1 when the workbook is opened
Private Sub UserForm_Initialize()


    ComboBox1.RowSource = ""
    ComboBox1.List = Worksheets("Drop Down List Source").Range("A2", Worksheets("Drop Down List Source").Range("A" & Rows.Count).End(xlUp)).Value
 
    ComboBox2.RowSource = ""
    ComboBox2.List = Worksheets("Drop Down List Source").Range("B2", Worksheets("Drop Down List Source").Range("B" & Rows.Count).End(xlUp)).Value
 
    ComboBox3.RowSource = ""
    ComboBox3.List = Worksheets("Drop Down List Source").Range("C2", Worksheets("Drop Down List Source").Range("C" & Rows.Count).End(xlUp)).Value
    
    ComboBox4.RowSource = ""
    ComboBox4.List = Worksheets("Drop Down List Source").Range("D2", Worksheets("Drop Down List Source").Range("D" & Rows.Count).End(xlUp)).Value
    
    ComboBox5.RowSource = ""
    ComboBox5.List = Worksheets("Drop Down List Source").Range("E2", Worksheets("Drop Down List Source").Range("E" & Rows.Count).End(xlUp)).Value
    
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Code:
Dim OneCell as Range
'...
With Worksheets("Drop Down List Source").Range("E:E")
    For Each oneCell in Range(.Cells(2,1), .Cells(Rows.Count,1).End(xlup)).Cells
        ChomboBox5.AddItem Format(oneCell.Value, "h:mm:ss")
    Next oneCell
End With
 
Last edited:
Upvote 0
I tried your suggestion, but I still can't get it to work. Would it be easier if I attached a copy of the file?
 
Upvote 0
Doesn't work isn't very specific.
What values do you have in column E? Are they strings or actual excel serial dates? (a formula like =ISNUMBER(E2) will distinguish between those)
What is shown in the combobox?
 
Upvote 0
The source column has times from 7:00:00 AM - 5:00:00 PM, in 30 minute increments.

I added the code below and now it displays the time in the correct format, once you select an option. However, the list that appears is displaying the times as a decimal value still.

Code:
Private Sub ComboBox2_Click()
    ComboBox2.Value = Format(ComboBox2.Value, "hh:mm AM/PM")
End Sub
 
Upvote 0
Deekappa

Do you want to have comboboxes which list the times 7:00:00 AM, 7:30:00 AM, ...., 5:00:00 PM or do the various columns on 'Drop Down List Source' have specific times?
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top