ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Decimal Number Format in ComboBox (https://www.excelbanter.com/excel-programming/369531-decimal-number-format-combobox.html)

Drummer361

Decimal Number Format in ComboBox
 
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!! :)


Paul Black

Decimal Number Format in ComboBox
 
Hi Drummer361,

Try something like :-

NumberFormat = "0.000"

Hope this Helps.
All the Best.
Paul

Drummer361 wrote:
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!! :)



Drummer361

Decimal Number Format in ComboBox
 
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!


Drummer361

Decimal Number Format in ComboBox
 
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")


Drummer361 wrote:
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!




All times are GMT +1. The time now is 03:47 AM.

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