ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Date Format In Combobox (https://www.excelbanter.com/excel-programming/389354-date-format-combobox.html)

IanC

Date Format In Combobox
 
sI have a Combobox whose RowSource is a list of dates for the current and
last year. When I display the dialog, the Combobox shows the dates as their
values as opposed to January 2007, etc.

Picking up on another thread, I have inserted in the activation code for the
dialog the command:

Me.MonthSelectedBox.Value = Format(Me.MonthSelectedBox, "mmmm yyyy") where
the Combo is called MonthSelectedBox. However, I still get the value.

Thanks in advance for any ideas.

Ian

merjet

Date Format In Combobox
 
It's not crystal clear to me what you mean. If the dates are formatted
in the cells of the RowSource as January 2007, then they appear that
way in the ComboBox when the entire list is shown. However, after
selecting one, such format isn't shown for the selected value. So I
guess that's what you mean. If you want the selected value formatted
in a particular way, then you probably need to not use RowSource and
populate the list like this.

Private Sub UserForm_Activate()
Dim c as Range
ComboBox1.Clear
For Each c In Sheets("Sheet1").Range("A1:A10")
ComboBox1.AddItem Format(c, "mmmm yyyy")
Next c
End Sub

Hth,
Merjet



IanC

Date Format In Combobox
 
The issue is that although the dates are formatted (e.g. as January 2007) in
the cells of the RowSource, when they appear the Combo they are shown as
their date value number.

Having said that, your solution works (thank you!) but, like you, I had
expected the formatting from RowSource to be duplicated in the control.


Ian

"merjet" wrote:

It's not crystal clear to me what you mean. If the dates are formatted
in the cells of the RowSource as January 2007, then they appear that
way in the ComboBox when the entire list is shown. However, after
selecting one, such format isn't shown for the selected value. So I
guess that's what you mean. If you want the selected value formatted
in a particular way, then you probably need to not use RowSource and
populate the list like this.

Private Sub UserForm_Activate()
Dim c as Range
ComboBox1.Clear
For Each c In Sheets("Sheet1").Range("A1:A10")
ComboBox1.AddItem Format(c, "mmmm yyyy")
Next c
End Sub

Hth,
Merjet





All times are GMT +1. The time now is 12:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com