简体   繁体   中英

Excel Column formatting or VBA

In excel, I want the numbers to be formatted in the column.

If we enter any other number then I want the number to have dash (-) after the fourth letter. For eg. if we enter 12345678 then I want it to convert to 1234-5678.

Thanks!

Use the escape character \\

eg number format 0000\\-0000

Enter the string above into a 'Custom' number format

from : http://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx

To do it with VBA:

Sub fmt()

    Range("A1").NumberFormat = "0000\-0000"

End Sub

JustinJDavies solution is correct except the escape character is not needed since "-" is not a custom format specifier. It does no harm, neither. So

Range("A1").NumberFormat = "0000-0000"

(It's working on my 2010. Sorry, not enough reputation to comment)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM