Decimal Number Format in ComboBox

D

Drummer361

Hello,

I am working on a project where I am defining the content of Combo
Boxes with the code below from the "UserForm Initialize" command:

For v = 13 To 16
ComboBox1.AddItem Worksheets("Worksheet1").Cells(v, 9).Value
Next v

This fills the data nicely in the combo boxes.

However, I am stuck with number decimal formatting. Let's say I want
all of the numbers in the ComboBox to have 3 decimal places of
accuracy, even if it lists xx.000. Does anybody have any code ideas to
work with the current code I have?

I appreciate any feedback!! :)
 
P

Paul Black

Hi Drummer361,

Try something like :-

NumberFormat = "0.000"

Hope this Helps.
All the Best.
Paul
 
D

Drummer361

Hi Paul, thanks for the quick response!

I just got it to partially work! Here is how I implemented the code:

For v = 13 To 16
ComboBox1.AddItem Format((Worksheets("Worksheet1").Cells(v,
9).Value), "0.000")
Next v

My issue now is that the initial number that displays before you click
on the ComboBox drop-down list isn't formatted. I must be overlooking
something on the UserForm Initialize command? It's formatted in the
Excel worksheet, and after I select a new value in the drop-down the
number I choose is formatted fine. Just the value on form load remains
without any decimal formatting.... any suggestions?

Thanks!
 
D

Drummer361

I figured it out!

Here is the code that runs from a module called in the
UserForm_Initialize command:

formUserForm1.ComboBox1.Value = Format(formUserForm1.ComboBox1.Value,
"#.000")
 

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