ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Userform Combobox to choose date (https://www.excelbanter.com/excel-programming/290721-userform-combobox-choose-date.html)

Rob

Userform Combobox to choose date
 
I'm having trouble, I think with formatting

Sub Userform_Initialise(
'First I populate my Combobox
Dim CountDateItem as Dat
For CountDateItem = Yesterday - 30 To Yesterday + 3
CountDate.AddItem CountDateIte
Nex

'The date is stored and displayed as text (mm/dd/yy)
'I need the date to be displayed as (dd/mm/yy
'Sometimse when I take the value from the combobox
'get the wrong date ("dd" and "mm" get swapped over

dim CombBoxDate as dat
ComboboxDate=countdate.valu
msgbox ComboBoxDat

I think I need to store the date as a date, and us
ComboBox1.Text = Format$(ComboBox1.Value, "mm/dd/yy"
but I can't work out how.

Also, am I populating the Combobox in the best way

Any help much appreciated

Thank
Rob

Dick Kusleika[_3_]

Userform Combobox to choose date
 
Rob

Comboboxes only store text, so you'll have to format your dates when you add
them to the cb.

CountDate.AddItem Format(CountDateItem, "dd/mm/yy")

Then when you retrieve the text from the cb, convert it back to a date.

ComboboxDate = DateValue(CountDate.Value)

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Rob" wrote in message
...
I'm having trouble, I think with formatting.

Sub Userform_Initialise()
'First I populate my Combobox:
Dim CountDateItem as Date
For CountDateItem = Yesterday - 30 To Yesterday + 30
CountDate.AddItem CountDateItem
Next

'The date is stored and displayed as text (mm/dd/yy).
'I need the date to be displayed as (dd/mm/yy)
'Sometimse when I take the value from the combobox I
'get the wrong date ("dd" and "mm" get swapped over)

dim CombBoxDate as date
ComboboxDate=countdate.value
msgbox ComboBoxDate

I think I need to store the date as a date, and use
ComboBox1.Text = Format$(ComboBox1.Value, "mm/dd/yy")
but I can't work out how.

Also, am I populating the Combobox in the best way?

Any help much appreciated.

Thanks
Rob




onedaywhen

Userform Combobox to choose date
 
Or use two columns: one hidden column with the actual date values and
one visible column with the date formatted as text.

--

"Dick Kusleika" wrote in message ...
Rob

Comboboxes only store text, so you'll have to format your dates when you add
them to the cb.

CountDate.AddItem Format(CountDateItem, "dd/mm/yy")

Then when you retrieve the text from the cb, convert it back to a date.

ComboboxDate = DateValue(CountDate.Value)

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Rob" wrote in message
...
I'm having trouble, I think with formatting.

Sub Userform_Initialise()
'First I populate my Combobox:
Dim CountDateItem as Date
For CountDateItem = Yesterday - 30 To Yesterday + 30
CountDate.AddItem CountDateItem
Next

'The date is stored and displayed as text (mm/dd/yy).
'I need the date to be displayed as (dd/mm/yy)
'Sometimse when I take the value from the combobox I
'get the wrong date ("dd" and "mm" get swapped over)

dim CombBoxDate as date
ComboboxDate=countdate.value
msgbox ComboBoxDate

I think I need to store the date as a date, and use
ComboBox1.Text = Format$(ComboBox1.Value, "mm/dd/yy")
but I can't work out how.

Also, am I populating the Combobox in the best way?

Any help much appreciated.

Thanks
Rob



All times are GMT +1. The time now is 09:42 AM.

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