Format Combo Box

L

LROCCO

Hi, I'm using the following code to look up a range to use for my
combobox list. The range has been formatted as date (dd/mm/yyy).
However, when it appears in the combobox list its shown as m/dd/yyyy.
Can anybody help.

CmBoxStartRange.List = Sheets("lvdtraw").Range("a5",
Sheets("lvdtraw").Range("a5").End(xlDown)).Value
 
D

Dave Peterson

Instead of using .list, you could use .additem and format the text the way you want.

cmboxstartrange.list = ""
cmboxstartrange.clear
with Sheets("lvdtraw")
for each myCell in .range("a5"),.Range("a5").End(xlDown)).cells
cmboxstartrange.additem format(mycell.value, "dd/mm/yy")
next mycell
end with

Personally, I'd use a format that was unambiguous -- like "dd-mmm-yyyy".

It scares me to have to guess what the user intended with 01/02/03.

(all untested and uncompiled -- watch for typos!)
 
L

LROCCO

Instead of using .list, you could use .additem and format the text the way you want.

cmboxstartrange.list = ""
cmboxstartrange.clear
with Sheets("lvdtraw")        
    for each myCell in .range("a5"),.Range("a5").End(xlDown)).cells
        cmboxstartrange.additem format(mycell.value, "dd/mm/yy")
    next mycell
end with

Personally, I'd use a format that was unambiguous -- like "dd-mmm-yyyy".

It scares me to have to guess what the user intended with 01/02/03.

(all untested and uncompiled -- watch for typos!)

Thanks again Dave, work fine
 
L

LROCCO

Thanks again Dave, work fine- Hide quoted text -

- Show quoted text -

How can this code be modified to only allow dates which are in the
list, i.e. user not allowed to enter their own date?
 
D

Dave Peterson

You can add a .stlye property to the combobox.

cbx.Style = fmStyleDropDownList
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top