View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Combobox / Data Problems

Do you have the a cell tied to that combobox--controlsource in its properties?

If yes, dump it and put the value in the cell in code.

Option Explicit

Private Sub ComboBox1_Change()

If Me.ComboBox1.ListIndex < 0 Then
Exit Sub
End If

With Worksheets("Sheet1").Range("b1")
.Value = Me.ComboBox1.Value
.NumberFormat = "mmmm dd, yyyy" 'whatever you want
End With

End Sub

But be careful.

Say your combobox shows Dec-03.

Excel will see that as a nice date--December 03 of the current year.

I would think that you would want to keep that date that gets selected as
unambiguous as possible:

Private Sub UserForm_Initialize()
Dim Varr As Variant
Dim i As Long
ComboBox1.RowSource = ""
Varr = Worksheets("Sheet1").Range("A1:A12").Value
For i = LBound(Varr, 1) To UBound(Varr, 1)
Varr(i, 1) = Format(Varr(i, 1), "mmmm dd, yyyy")
Next i
ComboBox1.List = Varr
End Sub



Matt wrote:

What goes back to the mm/dd/yyyy hh:mm format?


The dates in the drop down menu have the right date but they turn back
into mm/dd/yyyy hh:mm as soon as you hit enter or leave the combobox
...

You don't mean the selected item in the combobox, do you?


Yes, the date format of the combobox changes

If you put that value into a cell, maybe you can just format the cell the way
you want--either manually or in code???


Actually I use the combobox to select a date which then goes into a
different cell ... all those cells have the date format I need but in
the combobox its no cooperating :(


--

Dave Peterson