Reputation: 8188
Does anyone have any vb.net or vba code that will format excel values or a range of cells to have comma for 100s, 1000s,10000s etc.. and 2 decimal places only.
i.e. 10,256.45
Upvotes: 7
Views: 26299
Reputation: 1267
If you are using OfficeOpenXml excel range, do like this
rng.Style.Numberformat.Format = "##0.00";
Upvotes: 0
Reputation: 4761
If you don't need a specific custom formatting you can use Excel styles:
allRange.Style = "Comma"; // 1234.5678 -> 1,234.56
// or
allRange.Style = "Comma [0]"; // 1234.5678 -> 1,234
Upvotes: 1
Reputation: 57919
With a reference to the range:
rng.NumberFormat = "#,##0.00"
The current selection is also a range, so if you want it to work with the selection, just use:
Selection.NumberFormat = "#,##0.00"
Upvotes: 14