Combobox Format Problem

Passman

Board Regular
Joined
May 23, 2007
Messages
103
I am new to userforms and have a problem with the following code:

Private Sub cmdSelectDate_Click()

Sheet2.[AF1048].Value = comboSelectDate.Value
Unload Me

End Sub

Private Sub comboSelectDate_Change()

'comboSelectDate.Value = Format(comboSelectDate, "dd/mm/yy")

End Sub

What is happening is that the combobox selects the date from the range provided but when you click onto the command button it reverts to a date serial number. if I place the following code into the date change routine it shows correctly but the places text into the destination cell which the spreadsheet can't read. What I am looking for is for the date to show correctly in the combo box and be entered onto the spreadsheet as a serial date ie 39888.

I'm sure it is very simple but I can't find the answer having trawled through the forum. I would be grateful for some help.

Regards
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Have you checked the number formatting of the destination cell?

This put an Excel Serial date in A1 and automaticaly formatted the cell to "m/d/yy" when it did so. The two testing lines in the button's Click event help show what is happening with the cell.
Code:
Private Sub cmdSelectDate_Click()
    Sheet1.Range("A1").Value = comboSelectDate.Value
    MsgBox Sheet1.Range("A1").NumberFormat
    Sheet1.Range("A1").NumberFormat = "General"
End Sub


Private Sub UserForm_Initialize()
    With comboSelectDate
        .AddItem "5/23/08"
        .AddItem "6/23/08"
        .AddItem "4/20/09"
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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