Format SSN – Updated formula

Here is an update to the code I have posted on the site at

Format SSN

I realized that the last part of the formula doesn't check for dashes. Here is the updated formula:

=IF(AND(LEN(A4)>6, LEN(A4)<9,NOT(ISERROR(FIND("-",A4)))),A4,LEFT(A4,3)&"-"&MID(A4,4,2)&"-"&RIGHT(A4,4)))

Notice the addition of NOT(ISERROR(FIND("-",A4))) in the second IF formula.

If the formula already has dashes in it, it will simply return the value in A4.

Enjoy,
JP

Related Articles:

About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »

Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button
Comments on this article are closed. Why?

Site last updated: February 9, 2012