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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,348
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,191,025
Messages
5,984,197
Members
439,877
Latest member
kellylet

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
Top