Written by Allen Wyatt (last updated January 5, 2021)
This tip applies to Word 2007, 2010, 2013, and 2016
Sometimes when Eileen converts text to a table or if she imports a table from another program, some of the cells have a leading space in them, before the first actual character. She wonders if there is a way to use Find and Replace to remove these leading spaces only in the cells of the table.
There's actually one very quick way to get rid of the leading spaces without the need to use Find and Replace. Let's assume that you want the text in the cells to be left-aligned. Follow these steps:
That's it; when you perform step 3, the leading spaces are removed automatically by Word. Step 4 simply puts your text back to where you originally wanted it aligned. An extra bonus is that these steps actually remove any white space at the beginning of the text, not just spaces.
If you absolutely want to use Find and Replace to get rid of the spaces, you cannot do it using a single Find and Replace operation. Here's an idea of how you can do it using multiple passes:
Figure 1. The Replace tab of the Find and Replace dialog box.
Figure 2. The Find Style dialog box.
You could, if desired, also use a macro to remove leading spaces. All the macro needs to do is to step through all the cells in a table and trim off any leading spaces:
Sub DeleteCellLeadingSpace() Dim aCell As Cell Dim aRow As Row Dim cText As String If Selection.Information(wdWithInTable) Then For Each aRow In Selection.Tables(1).Rows For Each aCell In aRow.Cells cText = aCell.Range.Text cText = LTrim(cText) aCell.Range.Text = Left(cText, Len(cText) - 2) Next aCell Next aRow Else MsgBox "Insertion point must be in a table." End If End Sub
Note that when this macro stuffs information back into a cell (from the cText variable), it only stuffs back everything but the final two characters. If you don't do this, you'll end up with an additional hard return in each cell of the table.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1263) applies to Microsoft Word 2007, 2010, 2013, and 2016.
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!
Need a quick shortcut to jump to the top or bottom of a table column? Here's the two shortcuts you are searching for.
Discover MoreIf you want to have Word highlight rows in a table that contain a certain character, you need to resort to using a macro. ...
Discover MoreWord allows you to insert simple formulas, using fields, in table cells. If you want to see these formulas in their ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-01-31 18:26:35
Freyja Bibby
It is 11:24pm and I have to finish a word document with several tables incorporated into it so it's waiting in people's inboxes in the morning. So apologies if this seems like an over-reaction, but I LOVE YOU!
I was deleting from each cell manually - got through one table and decided there had to be a better way. Your align centre then left trick has just saved me at least an hour!
2020-09-02 23:14:27
Nancy
Hello, Allan,
I've tested this macro, and it works well normally. I've just noticed a problem. If tables has supercript texts, (as a reference), for exemple, in one cell, there is texts, plus a reference 1), 2), 3), etc., it makes all of my references back to normal text, thus 1), 2), 3), is now Normal Size Font, and not superscript.
I have applied this macro for all tables, imagine my surprise when I have 50 tables, with many References, I had to redo them one by one.
Is there a better way?
2019-11-09 16:58:21
Valdi
ok this centre then left align tip is the coolest one I've seen! I frequently paste from excel to word and frequently get leading and trailing spaces. that up till now I removed with advances search and replace. I came here looking for a macro to make it simpler and THIS is much much easier!! Thank you.
2017-02-21 19:12:08
Gretchen
That center-and-left tip is AWESOME!! This will save me a LOT of time. THANK YOU!
2017-02-20 08:57:16
Bob
Centering and changing back to Left Align gets rid of the leading spaces whether in a table or not. I had a specific instance of copying addresses from our website to a doc and did not know this. Works great! Thanks!
2017-02-18 09:08:47
Joann Ingoglia
You know yr stuff!
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments