Removing Extra Paragraph Marks

Written by Allen Wyatt (last updated November 12, 2021)
This tip applies to Word 2007, 2010, 2013, and 2016


12

There may be times when you are working with a document when you have a need to remove extra paragraph marks. This is particularly true if you are working with an ASCII file or a file that may have originally been formatted with another word processor. This process of manually removing extra paragraph marks can be very time consuming.

If you find yourself in this situation, you may find this macro of interest. It removes extra paragraph marks from a document. When it is completed, there should not be even two paragraph marks in a row in your document.

Sub ReplacePara()
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "^p^p"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    While Selection.Find.Found
        Selection.MoveRight Unit:=wdCharacter, Count:=1
        Selection.TypeBackspace
        Selection.MoveLeft Unit:=wdCharacter, Count:=2
        Selection.Find.Execute
    Wend
End Sub

There are two parts to this macro. The first part—which relies on the Selection.Find method—uses Word's built-in find and replace capabilities to find all instances of two paragraph marks in sequence. The macro doesn't replace the sequential paragraph marks; it simply finds them. Then the second part of the macro kicks in—using the Selection.Find.Found—property to delete the second of the two sequential paragraph marks.

The reason this approach is taken is because it leaves the formatting correct on the remaining paragraph mark. For instance, if the two sequential paragraph marks use different formatting from each other, the formatting of the first paragraph mark remains unchanged. If you simply replaced the sequential paragraph marks with a single paragraph mark, it is possible that you may not have the formatting exactly as you want when the replacing is finished.

Note that Selection.Find.Found is used as a "flag" for the While loop. This property reflects the status of the latest Find operation. If True then the search was successful; if False, then there was nothing found (and, therefore, nothing to change).

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 (998) applies to Microsoft Word 2007, 2010, 2013, and 2016.

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

Creating Multiple Highlighter Tools

Some people, while developing documents, like to use the Highlighter tool quite a bit. It can quickly get monotonous, ...

Discover More

Adding and Formatting a Shape via Macro

Excel makes it rather easy to add shapes to your worksheets. If you add a lot of shapes, you quickly discover that it can ...

Discover More

Adjusting Navigation Pane Font Size

The Navigation pane can be quite handy for quickly jumping to different areas of your document. If the size of the text ...

Discover More

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

More WordTips (ribbon)

Using the Object Browser

Efficiently navigating through a document, particularly as it gets longer, can be a perpetual challenge. One tool you can ...

Discover More

Inserting a Non-Breaking Space

In Word a non-breaking space will help you keep two words together on the same line. Here's two different ways that you ...

Discover More

Deleting a Final Blank Page

When creating a document, if can be frustrating to have a blank page somehow appear at the end of the document. If you ...

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 9 + 3?

2016-10-06 08:07:55

Lee Batchelor

Thanks for the tip, Truis! I shall modify my macro.

- Lee


2016-10-05 23:37:04

Truis

Great stuff! This code is exactly what I needed for a macro that tidies up the formatting of text pasted in from elsewhere. In this case, it's important to use Backspace, because I want Word to retain the formatting of the second paragraph mark, not the first. That bit's working well.

Unfortunately, I'm having trouble with the While/Wend, because it's deleting *too* many characters, not just the paragraph marks. I think that's because the source of what my macro is pasting in (as unformatted text) is the content of a Content Control. Two steps forward, one step back...!

Tip! If finding "^p^p" finds no results (when you know they exist), try finding "^013^013" instead. That's the full character code, rather than the "^p
", which is like an internal shortcut key.


2016-08-28 08:49:47

Lee Batchelor

Yes, the macro crashes Word 2007 too, when there is a table in the document.

I tried the Find and Replace method with or without a table. It doesn't get rid of the empty paragraphs in Word 2007. Why not?

I typed:
Find what: ^p^p
Replace with: ^p

It found two paragraphs in a row (the first with content, the second with nothing, which must be deleted), and it didn't do anything!!


2016-08-27 11:49:02

Lyn Imeson

This macro doesn't seem to work if there are tables in the file. It makes Word crash.
Could anyone suggest a modification?


2016-08-25 08:08:47

Lee Batchelor

Good catch, Lisa!

I just ran the macro without removing the space, and only those empty paragraphs without the extra space were cleared.

I wonder if someone can modify this macro to account for the extra space.


2016-08-24 11:53:31

Lisa Herider

I have found many paragraph marks preceded by a spaceband. Before you run this macro, do a search/replace for the spaceband and ^p in your search string replacing with just the ^p. That way when you run the macro it will find all the paragraph returns.


2016-08-22 12:30:58

Macro is faster

Using a macro is much faster if someone hit enter 20+ times. Set it one and give it a keyboard shortcut, or assign a button to it in the QAT and you are all set. Saves a ton of time.


2016-08-22 10:44:29

Sarita King

Macro Schmacro..do a find and replace with the following
FIND ^p^p
REPLACE ^p

run it until it stops.
Note bonus the code for tab is ^t


2016-08-22 03:34:59

George JasonSmith

I agree with Min (below) and have been using fAnd and replace to do this for years. also I find it easier to type ^p ^p into the find box and ^p into the replace, rather than navigating the Choose box


2016-08-21 09:09:18

Lee Batchelor

Agreed, Min. I've used your method too. I've also noticed it can mess up the formatting of some paragraphs that have styles applied when I fill in the Replace field with nothing (leave it blank). By placing one paragraph mark in the Replace box, you still have one empty paragraph where the user had two originally, correct? Empty paragraphs are a no-no.


2016-08-20 10:01:49

Min Edwards

Actually you don't need a macro to do this do you? I take out those multiple paragraph marks just with Find/Replace. Some of my clients add multiple marks instead of a page break so you can imagine how many paragraph marks they insert. With Find choose Special then choose Paragraph Mark, then another paragraph mark. In the Replace box, just put one Paragraph mark. You may have to do this multiple times if there are lots of para marks strung together.


2016-08-20 09:19:40

Lee Batchelor

What a wonderful macro! I often import documents where the person has used the Enter key to create extra paragraph spacing, instead of controlling the Before and After paragraph spacing using styles. So many people treat word processors like typewriters, which is mostly wrong.

It's so sad that to create handy macros like this one, we must learn a very complex language like VBA. We can’t expect Microsoft to anticipate all our individual writing needs, but if we only had a tool that easily lets us create macros, we could customize Word the way we want it. The Record Macro tool is handy but very limited.

Thanks for this wonderful macro!


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.