How to change the default number format in Excel?

前端 未结 6 622
不思量自难忘°
不思量自难忘° 2021-01-18 19:31

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,

6条回答
  •  星月不相逢
    2021-01-18 20:12

    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)

提交回复
热议问题