0

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!

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.