Format Column as Decimal (VBA)

David Schaleger

Board Regular
Joined
Dec 6, 2010
Messages
55
I need VBA code to convert a column's (B, in this case) cell number format from the default "general" to 2-digit decimal. Thank you.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Range("B1").EntireColumn.NumberFormat = "#.00"
Since we are doing the whole column, it is simpler to just use Columns instead of Range...

Columns("B").NumberFormat = "0.00"

Note: I prefer using "0.00" instead of "#.00", hence my change in the assigned value.
 
Upvote 0
Sorry, I should be more specific. The Excel file is created from an export utility. So the VBA code's probably going to have to go in the Personal Excel file. Whenever the exported file is opened, that's when the column needs to be formatted as decimal. The file will originally be exported as LTXNMMDD.csv, but part of an as-of-yet undetermined routine will rename the MMDD to the current 2-digit month and day. Not sure if this information is important or not, but there you go.
 
Upvote 0
Thank you. How do I make this happen "on open"?
This question has me a little confused. It would indicate that you always want Column B to have the cell number format of "0.00", but if that is the case, then why not simply select the column, apply the Cell Format normally (not with VB, but using Excel's Cell Format functionality) and Save the workbook? Once you do that, Column B will always have the indicated cell number format. Or are you saying your code or, heaven forbid, your users will change the columns cell format during its use?
 
Upvote 0
The idea is to have the exported file formated (decimal), renamed, then emailed to another user ready to upload into another system. We don't want anyone along the way to have to do anything manually. Unfortunaly, the export utility can't format the column, so it's up to VBA or, Heaven forbid, a user!
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top