I have this column of string integers in the \'general\' type all the time. Every time I open this spreadsheet, I have to convert it into \'number\' type. But when I do it,
Try the following:
Right click on a column and click on Format Cells...
and then select Number
from Category:
list and for Decimal places:
specify 0
Save the file and re-open, and you should see that column be set to Number
EDIT:
If you want to apply formatting to multiple excel files, you can write a macro for that:
Doing some quick research, came across the following VBA code --- I DO NOT take credit for this. I did however changed the
DoWork
method to add:.Worksheets(1).Range("A1").NumberFormat = "Number"
Sub ProcessFiles()
Dim Filename, Pathname As String
Dim wb As Workbook
Pathname = ActiveWorkbook.Path & "\Files\"
Filename = Dir(Pathname & "*.xls")
Do While Filename <> ""
Set wb = Workbooks.Open(Pathname & Filename)
DoWork wb
wb.Close SaveChanges:=True
Filename = Dir()
Loop
End Sub
Sub DoWork(wb As Workbook)
With wb
'Do your work here
.Worksheets(1).Range("A1").NumberFormat = "Number"
End With
End Sub
Set the format as follows:
Once the file is saved the format will be retained.
Excel Tips, Learn Excel \ Raghu R
Setting Formatting Options for Workbooks
Excel does not offer many options that allow you to set formatting defaults for your workbooks. However, you can work around this by modifying the formatting in a blank workbook, then saving it as the default template.
- Open Excel to a blank workbook.
- Format the blank file with all options desired. For example, set margins, cell color formats, or set up a header or footer. Make sure to remove any values you entered in cells to test formatting unless you want them to appear in every blank workbook.
- Once your changes are made, click on the File tab and choose Save As.
From the “Files of type” drop-down list, select “Excel Template (*.xltx)” and change the file name to “Book.”
Set the “Save in” location to theXLSTART folder. This folder is typically located in a path similar to
C:Program Files/Microsoft Office/Office14/XLSTART
.
- The quickest way to find its location is to use the Immediate window in the Visual Basic Editor (VBE), as follows:
- Press Alt+F11 to launch the VBE.
- If the Immediate window isn’t visible, press Ctrl+G.
- In the Immediate window, type
? application.StartupPath
and press Enter.- VBA will display the path to XLStart.
- Click Save.
- Quit and re-open Excel. The blank workbook should contain the formatting you previously set.
I thought number format was stuck on a date and was reading this post to fix the problem when I realized the following.
Changing the number format in the Home Ribbon to, in my case, General that the next time I opened Excel (Office 365 Subscription version) the General format stayed! Problem solved.
Home Ribbon, Number Format screen capture
wrote a tiny macro
Sub PERS_FormatSelectionToNumberNoDecimals()
Selection.NumberFormat = "0"
End Sub
... in my PERSONAL.XLSB.
In my data workbook's ThisWorkbook module (VBA editor) I place a function
Private Sub Workbook_Activate()
' Purpose : assign key shortcuts when workbook is activated
Application.OnKey "^+o", "PERSONAL.XLSB!PERS_FormatSelectionToNumberNoDecimals"
End Sub
... to assign the shortcut key CTRL-SHIFT-O (O as in other; you may assign another key of your choice) to the macro.
=> whenever you need to re-format a range to Number with 0 decimals, select the range and press the shortcut key.
In order to get rid of the key assignment when switching to another workbook you may place
Private Sub Workbook_Deactivate()
' Purpose : removes key short cut assignments if workbook is deactivated
Application.OnKey "^+o"
End Sub
...in my data workbook's ThisWorkbook module (VBA editor)
If you want to put these styles into effect only if you select them (i.e., not as the default format for when you create a new file), then one way you can do it is to create new styles within that template (e.g., Book.xltx). For example, you can create a new style called "Currency (0)" that is equivalent to the style $#,##0 for positive numbers. So, to use the desired format you would change the style of cell instead of using the formatting controls.
Yes, this is not ideal (it would be better to be able to change Excel's default functionality directly), but it does work.