2017-08-14 58 views
0

我想从组合框的窗体中的单元格中插入日期。我让我的按钮看起来像我想要的样子,但是当我在单元格中插入日期时以文本格式显示。如何以日期格式设置单元格中的值?从组合框的单元格中插入日期

Private Sub UserForm_Initialize() 

Dim i As Integer 

Combobox1.List = Worksheets(3).Range("AM3:AM13").Value 

For i = 0 To Combobox1.ListCount - 1 
    Combobox1.List(i) = Format(DateValue(Combobox1.List(i)), "dd mmm") 
Next i 

End Sub 


Private Sub ComboBox1_Change() 
'Nothing here 
End Sub 

Private Sub InsertButton_Click() 
    ActiveCell.Value = Combobox1.Value 
End Sub  

感谢

+0

'ActiveCell.NumberFormat = “{挑选您的格式}”'你添加日期之前。 –

+0

感谢您的回答,但它不起作用。这改变了单元格的格式,但在该单元格之后的单元格是文本格式。我认为有必要改变这里: 'Combobox1.List(i)= Format(DateValue(Combobox1.List(i)),“dd mmm”)' –

+0

你使用什么格式? “dd mmm”对我来说工作得很好(但是由于你的组合框没有年份,它将默认工作表中的当前年份)。 –

回答