user3777959
user3777959

Reputation: 1

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!

Upvotes: 0

Views: 137

Answers (2)

jemenfou
jemenfou

Reputation: 68

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)

Upvotes: 0

JustinJDavies
JustinJDavies

Reputation: 2693

Use the escape character \

e.g. 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

Upvotes: 1

Related Questions