Format Combo Box To Date Format

Makpo

New Member
Joined
Sep 23, 2011
Messages
28
Does Anyone know how to format a combo box to display as dates rather in a general format.

I have some dates on a table linked to a combo box drop down. When selected on the drop down, it keeps presenting in a general number format.

please help
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Code:
Dim i As Long

With ComboBox1
    For i = 0 To .ListCount - 1
        .List(i) = Format(.List(i), "mm/dd/yyyy")
    Next i
End With
 
Upvote 0
Alternatively, you could use a Forms Control combo box instead of ActiveX depending on your need.
 
Upvote 0
Hi Mikerickson,

I tried it but it didnt work. my combo box is on a userform. am I to use the code within the command button click or on the combo box click itself?

Assuming its a subroutine on its own?
 
Upvote 0
I tried the code below and it displayed date format on the combo box correctly but entered a wrong month and year on the data (it seems to be a default date year of 1900) but the day was correctly entered.


Code:
Private Sub cboeDate_Change()
    
    With cboeDate
        .value = Format(.value, "dd/mm/yyyy")
    End With
      
End Sub
 
Upvote 0
Thanks, I already changed it from mm/dd/yyyy to dd/mm/yyyy but it still didnt work.

I resorted to hiding the visibility of the numbers on the combo box and settled for just the drop down arrow to show the dates without the code, since it copies correctly to my desired location.

not the best but I'll make do. Thanks again
 
Upvote 0
I think this is what you were looking for on the combobox. Right click on your Userform in your VBA project explorer and choose View Code and pop this in:

Private Sub ComboBox1_Click()
ComboBox1.Value = Format(ComboBox1.Value, "dd/mm/yyyy")
End Sub
 
Upvote 0
Thanks CWatts,

But Not exactly, it displays the value of the date as a date, only to populate the target cell with the month and year wrongly to a default of /01/1900. The day is however pasted correctly
 
Upvote 0
Hrm. The only thing I can think of is that it's somehow passing text, which has a numerical value of 0, which would be a d/m/yyyy of 0/1/1900

Try using datevalue:

Private Sub ComboBox1_Click()
ComboBox1.Value = Format(DateValue(ComboBox1.Value), "dd/mm/yyyy")End Sub
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,421
Members
452,913
Latest member
JWD210

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