Question : Excel control returns only a string

I have an activex combo box linking to a cell that is formatted to be a number.  The list is forced to display as a date but the return is a #.  It continues to show up as number formatted as text in the linked cell.  If I hit ENTER in the linked cell it quickly changes to a # and all my formulas then work fine.  The only way I get around it is below.  Any better way or what am I missing.

B124 on the control sheet is the linked cell.  Again it is a formatted # cell.
F_startDate has a list of dates that I force to show as xx/xx/xx

thanks experts
1:
2:
3:
4:
Private Sub F_StartDate_Change()
    F_StartDate.Value = Format(F_StartDate.Value, "mm/dd/yyyy")
    Sheets("control").Range("B124").Value = Sheets("control").Range("B124").Value
End Sub

Answer : Excel control returns only a string

Since a combobox returns a string, it's not surprising that the linked cell is getting messed up. I suggest not linking the combobox to a cell, but instead using VBA code to update the value.

The snippet below shows both a KeyUp and LostFocus sub so the date cell (A1 in the code) is updated when you are done typing in the combobox.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
Private Sub ComboBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim v As Variant
If KeyCode <> 13 Then Exit Sub
On Error Resume Next
v = CDate(ComboBox1.Value)
If Not IsError(v) Then Range("A1").Value = v
On Error GoTo 0
Range("A1").Select
End Sub

Private Sub ComboBox1_LostFocus()
Dim v As Variant
On Error Resume Next
v = CDate(ComboBox1.Value)
If Not IsError(v) Then Range("A1").Value = v
On Error GoTo 0
End Sub
Random Solutions  
 
programming4us programming4us