Inserting Dashes between Letters in Words

Written by Allen Wyatt (last updated March 2, 2024)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021


Lorraine often works with transcripts of interviews. Interviewers will ask interviewees to spell out their names. When she types these up, she needs to insert dashes between letters to show they are being spelled, as in J-O-H-N D-O-E. Lorraine wonders if there is a way to select the name and then run a macro to capitalize the name and insert the requisite dashes between letters.

Macros are very well suited for doing this type of text processing. In fact, there are probably a dozen or so ways you could approach the problem in your macro. The following is a rather simple way to do it:

Sub CapDashNames()
    Dim sTemp As String
    Dim sName As String
    Dim J As Integer

    sTemp = UCase(Selection.Range.Text)   ' Make all uppercase
    If Len(sTemp) > 1 Then
        sName = ""
        For J = 1 To Len(sTemp) - 1
            ' Add new character to name
            sName = sName & Mid(sTemp, J, 1)
            If Mid(sTemp, J, 1) >= "A" And Mid(sTemp, J, 1) <= "Z" Then
                ' Add a dash if character was a letter
                sName = sName & "-"
            Else
                ' Character added was not a letter
                If Mid(sName, Len(sName) - 1, 1) = "-" Then
                    ' If there is a dash just before non-letter,
                    ' get rid of it
                    sName = Left(sName, Len(sName) - 2)
                    sName = sName & Mid(sTemp, J, 1)
                End If
            End If
        Next J
        ' Add final character
        sName = sName & Right(sTemp, 1)
        Selection = sName
    End If
End Sub

Basically, the macro steps through whatever you've selected and adds a dash after each alphabetic character. If that dash is then followed by a non-alphabetic character, then the dash is removed. (That way you don't, for example, end up with a dash before or after a space.)

In order to use the macro, simply select the name you want to modify, and then run the macro.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1354) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Deleting MRU Entries

By default Word dutifully keeps track of the different files you've worked on in the past. If you want to delete an entry ...

Discover More

Hanging Indents in Wrapped Text

If you use hanging indents for some of your paragraphs, you may wonder why they don't look right when they wrap on the ...

Discover More

Automatically Adjusting Height for Text Boxes

Text boxes are often used to enhance the layout of documents. You may want a text box that adjusts its height ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Using Optional Hyphens

Adding hyphens to your document can affect the way in which Word wraps text from one line to the next. Optional hyphens, ...

Discover More

Pasted Text Looks Like Hollow Squares

When you paste something into your document, you expect it to at least be readable. If, instead of letters, you see small ...

Discover More

Selecting a Word

Selecting text is a critical skill to possess when you want to work with a Word document. This tip explains how you can ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 1 + 1?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.