One item I’ve learned from using computers is that there is usually more than one way to solve a problem. This week two people approached me with a similar problem. They were trying to get a simple, but long address list from Microsoft Word into Microsoft Excel. One tried to use macros and the other resorted to cut and paste. In each case, I thought a simpler solution involved Word’s Search and Replace feature. Here’s Part 1 of a two-part tutorial.
Each user was starting with a list of names and addresses that were in Microsoft Word. I suspect they were some sort of address directory or contact list. For various reasons, they needed to get the data into Microsoft Excel. They wanted one row for each record. The address record looked like the records below.
James Madison
124 Main St
Anytown, NY 12345
Paula Harris
356 Longtree View
Harper, MA 01073
Before starting, review your list and look for common denominators and possible exceptions. In these cases, the records were uniform with each one consisting of three lines with a blank line between.
Creating the Record Delimiter
The first step in this process is to add a record delimiter. This is the item Excel will look for to separate each row.
Your Find and Replace dialog should look like the one below.
- Copy the text you wish to convert and paste it to a new document.
- Turn on Paragraph marks using the Standard toolbar button or Ctrl+Shift+*
- Notice how two paragraph marks exist between each record. If your last record doesn’t show tow, you might want to add a line at the end. We’ll substitute a unique character as a record delimiter. I like to use the tilde ~ sign, but you can use any uncommon character. Be careful not to use a character that appears in your list.
- Go to the top of your document. (Ctrl+Home)
- From the Edit menu, select Find…
- Click the Replace tab
- Click the More button at the bottom. Your dialog will now show more options.
- Click the Special button.
- Select Paragraph Mark from the pop up menu. Repeat this step.
- Enter in the symbol you wish to use for your record delimiter such as a tilde.
- Click Replace All.
- Click Close.
Microsoft Word will give you a count of how many replacements it made. Don’t worry that your formatting looks off and various lines look combined.
Defining the Fields
The next part is to define our fields which will be placed in Excel columns. Each record had 3 lines which represented: Name, Address and City, ST and Zip. In this example, we’re going use a comma to separate these fields. We can parse the names and state in Excel later.
- Go to the top of your document.
- From the Edit menu, select Replace.
- Your Find and Replace dialog will have your previous values. Remove one of the paragraph marks sets in the Find what: text box.
- In the Replace with: text box, clear out the tilde and enter a comma.
- Click Replace All
- Click Close.
Breaking Apart the Records
Your document probably looks worse, but don’t worry about it. Part of this may be word wrap and part of it is our formatting. The next steps will put it into perspective.
- Go to the top of your document
- From the Edit menu, select Replace.
- Your Find and Replace dialog will have your previous values. Remove the paragraph mark in the Find what: text box and type in a tilde.
- In the Replace with: text box, clear out the tilde
- Click Special
- Select Paragraph Marks from the pop up menu
- Click Replace All
- Click Close.
If you have extra commas or paragraph marks on the last line, you can delete them. If you’re really fastidious and don’t like the space before the State, you can do another search and replace. Personally, I would do this in Excel with ASAP Utilities which is a free add-on.
Saving the File
Your document should now have 1 record per line with the fields separated by a comma and ending with a paragraph mark. There will not be a comma between state and zip code.
- From the File menu, select Save As
- In the Save As dialog, enter your file name
- In the Save as type: drop down menu, select Plain Text.
- Word may display a File Conversion dialog with a warning that all formatting will be lost. Don’t worry and click OK to accept the default values.
Pulling the File into Excel
The last part is to import our Microsoft Word text file into Excel.
- Open Excel
- From the File menu, select Open
- In the Open dialog, change the Files of Type: entry to Text Files
- Point to your .txt file.
- Click Open
- The Text Import Wizard should start. Keep the default values and click Next.
- In Step 2, change your Delimiter from Tab to Comma. The screen should adjust to show the fields in columns.
- In Step 3, you can change the data format for each column or click Finish to accept General format.
Final Tweaks
Chances are you will want to do some minor tweaking. As example, you probably want to add column labels. Also, if you have US addresses, you may want to split the last column that has the State and Zip code combined. You may also want to split the name column into first and last names. In our example, this is easy as a space separates the first and last name or the state and zip code.
To parse a column into multiple columns,
- Highlight your column
- From the Data menu, select Text to Columns…
- Click the Next button on the Convert Text to Columns Wizard
- In the Delimiters box for Step 2, select Space
- Click Next
- Define your data format.
(Note: For zip codes, you may want to change the data format to Text if you have zip codes starting with “0”.)
While these steps may not work exactly for your list, they should provide the basis for creating the records in Microsoft Word. Your list may be slightly different or include more items such as email addresses. Either way, you could use similar steps to create a document that Microsoft Excel can interpret. In Part 2, we will use tables to accomplish a similar result.