Nudging a Table

Written by Allen Wyatt (last updated May 1, 2020)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


1

Ray wonders if there is a way to move an entire Word table vertically, pixel by pixel. Everything he has read indicates that grabbing it and holding the Alt key will allow for that, but it does not work smoothly.

I'm not sure where Ray has been reading, but the Alt key does not allow for nudging tables. In fact, it doesn't seem to work for table movement at all, with one exception—if you press Shift+Alt and then use the up or down arrow keys, the table is moved up or down an entire paragraph in your document.

Other keystroke combinations don't work either. You would think that nudging tables would work as it does for other objects within a document—you select the object and then use the arrow keys to give the nudge. However, it doesn't work with tables at all. If you select the table and then press the up or down arrow keys, then Word deselects the table and moves the insertion point either above or below the table in the document.

There are a couple of workarounds you can use, however. First, you could adjust how you put your tables in the document. Simply put them within a text box, and then you can use the arrow keys to nudge the text box. (You can also format the border on the text box so it doesn't show.)

Another workaround is to use a macro to do the movement. The following macro will move the table a single pixel up:

Sub MoveTableUp1()
' set pxl to the number of pixels to move: positive for down and
'   negative for up
    Const pxl As Single = -1

    If Not Selection.Information(wdWithInTable) Then Exit Sub
    With Selection.Tables(1)
        .Rows.VerticalPosition = .Rows.VerticalPosition + PixelsToPoints(pxl)
    End With
End Sub

All you need to do is make sure that the insertion point is within the table you want to nudge. If you want to move the table down instead of up, simply change the definition of the pxl constant to be a positive 1 instead of a negative 1.

There is something else you should note about this macro—it may mess up your document layout. You see, the VerticalPosition property is only effective if your table is configured to allow text to wrap around it. (This is configured in the Table Wrapping area of the Table Properties dialog box.) Recognizing this, when you use the macro to adjust the VerticalPosition property, it automatically changes the table from "none" to "around." This, obviously, could affect the page layout if you didn't previously have wrapping turned on and the table is narrower than your text area.

There is another potential "gotcha" here, as well. You might think that you can adjust the horizontal position of the table by changing the VerticalPosition property in the above macro to HorizontalPosition. This seems logical, but how it works in the macro may throw you for a loop. Where adjusting the VerticalPosition property will change the table wrapping from "none" to "around," adjusting the HorizontalPosition property will not. Instead, on some versions of Word, it will give you an error.

The safest way to deal with all of these quirks is to adjust the macro to make sure that it only adjusts a table if its wrapping property is set to True, in this manner:

Sub MoveTableUp2()
    Dim sTemp As String

' set pxl to the number of pixels to move: positive for down and
'   negative for up
    Const pxl As Single = -1

    sTemp = ""
    If Selection.Information(wdWithInTable) Then
        With Selection.Tables(1).Rows
            If .WrapAroundText Then
                .VerticalPosition = .VerticalPosition + PixelsToPoints(pxl)
            Else
                sTemp = "Table is inline. No action taken."
            End If
        End With
    Else
        sTemp = "The insertion point is not within a table. No action taken."
    End If
    If sTemp > "" Then MsgBox sTemp
End Sub

This variation of the macro also includes a bit more feedback for the user so that if no action is taken, the user is told why this is the case.

If you prefer, you can move the table a point (1/72 of an inch) at a time. Here's the version of the macro that could handle this movement:

Sub MoveTableUp3()
    Dim sTemp As String

' set pt to the number of points to move: positive for down and
'   negative for up
    Const pt As Single = -1

    sTemp = ""
    If Selection.Information(wdWithInTable) Then
        With Selection.Tables(1).Rows
            If .WrapAroundText Then
                .VerticalPosition = .VerticalPosition + pt
            Else
                sTemp = "Table is inline. No action taken."
            End If
        End With
    Else
        sTemp = "The insertion point is not within a table. No action taken."
    End If
    If sTemp > "" Then MsgBox sTemp
End Sub

As already discussed, nudging the table horizontally instead of vertically is simply of matter of using the HorizontalPosition property with the Rows object rather than the VerticalPosition property. Remember, though, the caveats discussed, as well, as to how the HorizontalPosition property differs in use from the VerticalPosition property. With this in mind, you could rather easily create four versions of your macro (for each of the four directions you might want to nudge your table) and then assign shortcut keys to the macros.

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

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

Selecting a Column or Row in a Table

Selecting rows and columns in tables is a common task. Because of this, Word provides a couple of ways you can accomplish ...

Discover More

Creating Custom Chart Formats

Excel allows you to create custom chart formats that go beyond the standard formats provided in the program. You can then ...

Discover More

Quick Recall of Table Formats

Got a table that you use over and over again? One way you can make quick work of such repetition is to save the table in ...

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)

Viewing Formulas in Table Cells

Word allows you to insert simple formulas, using fields, in table cells. If you want to see these formulas in their ...

Discover More

Putting Something in Every Cell of a Table

Need to make sure that all the cells of a table have something in them? It's easy to do with a handy little macro.

Discover More

Formatting an ASCII Table with Spaces

When you get a text file from a program other than Word, tabular information may be formatted with nothing but spaces in ...

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 2 + 2?

2018-08-11 07:25:37

Al Wilson

Sorry, but for me this macro does not work. Well, at least works in a strange way. The Macro for moving Up and Down actually move my table left and right, whereas my modified version using HosizontalPosition causes an error 9118 Parameter value was out of accepted range. This was when using pxl parameter as either 1 or -1. Basically no change to the macro other than changing VerticalPosition to HorizontalPosition.

Can't understand the issue unless it thinks my document is in Landscape mode (It is in portrait) but that would not explain the 9118 error.
I assume HorizontalPosition can be incremented or decremented by a Single of either 1 or -1?

Edit. Up and Down work correctly but using HorizontalPosition causes the error 9118. I am using Word 2016.


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.