VBA - Passing Array of dates to Combobox / Listbox

Hi there,

I have a list of dates in a range on a worksheet that I use to populate a combobox.  I have formatted the dates as "dd-mmm-yy".  When it gets passed to the control, it loses the formatting I prefer and instead formats as "dd/mm/yyyy".  

I hope I am being stupid and there is an easy property somewhere that allows me to switch such that it sticks with the format I prefer, but regardless, does anyone have any suggestions as to how to pass the dates to the listbox (other than one at a time as a string), to avoid the change in formatting.

Just for reference the code I am using is as follows:

varImport = Application.WorksheetFunction.Transpose(wksMain.Range("Import_Qtrs").Value)
frmSelectQtrs.cmbQtr1.Clear
frmSelectQtrs.cmbQtr1.List = varImport

Many thanks,

Digittt
DigitttAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KendorCommented:
it should be possible to set:
ComboBox1 = Format(ComboBox1, "dd-mm-yy")

or there is a propery called
.NumberFormat = "dd-mm-yy"

0
RichardSchollarCommented:
Hi

You could use Evaluate to generate a 2D array in the correct format like this:

However, it would quite possibly be faster (not that you're likely to notice in the real world) to assign the values via a 2D array and then add them one at a time via the Add method of the combo.

Richard


varImport = Application.WorksheetFunction.Transpose(Evaluate("IF(ROW(),TEXT('" & wksMain.Name & "'!" & wksMain.Range("Import_Qtrs").Address & ",""dd-mmm-yy""))"))

'and then assign this:

frmSelectQtrs.cmbQtr1.Clear
frmSelectQtrs.cmbQtr1.List = varImport

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HyperBPPCommented:
I couldn't find a flag to set, but this works.
varImport = Application.WorksheetFunction.Transpose(wksMain.Range("Import_Qtrs").Value)
For Item = 1 To UBound(varImport)
    varImport(Item) = Format(varImport(Item), "dd-mm-yy")
Next Item
frmSelectQtrs.cmbQtr1.Clear
frmSelectQtrs.cmbQtr1.List = varImport

Open in new window

0
DigitttAuthor Commented:
Evaluate worked, although I have no idea why...haven't used it before....hmmm, a new toy to play with.

I tried the Format / .NumberFormat options, they were a no-go, but thanks for the idea.  

On the For Next, I didn't want to iterate through it individually but it would work.  No one would notice given the size of the array but I was looking for something more contained that didn't have to do it one at a time.

Thanks all for the suggestions.

Digittt
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.