Welcome to Office Zealot Sign in | Join | Help

If the columns and rows are messed up when copying items to Excel from an Outlook view...

As the subject (“If the columns and rows are messed up when copying items to Excel from an Outlook view...“) says, if you've experienced this and want a fix, then read on!  If you don't know what I mean, go to your Contacts folder and select the Phone List view.  Now add the Business Address Street column to the view (bring up the Field Chooser dialog first), select all the items in the grid, copy, and paste into a new Excel spreadsheet.  If you didn't know you can do that, then that's my bonus tip of the day.  :-)

So, if you have any Contacts that contain multiple lines of information (usually 2) in a street field, Excel interprets the carriage return character as a column break; this cause things to get shifted around rather terribly and you may wind up with extra rows containing only one column of data.

So here's the trick...

Using handy ol' VB functions, we can create formula fields that will split these lines into two separate columns.  Display the Field Chooser dialog, and click the New button.  In the Name box, enter “Business Address Street Line 1”, choose Formula for the Type, and paste this into the Formula box:

IIf(Left([Business Address Street],InStr([Business Address Street],Chr(10)))="",[Business Address Street],Left([Business Address Street],InStr([Business Address Street],Chr(10))-1))

Do the same for a second field called “Business Address Street Line 2”, and use this Formula instead:

IIf(InStr([Business Address Street],Chr(10))>0,Mid([Business Address Street],InStr([Business Address Street],Chr(10))+1,Len([Business Address Street])-InStr([Business Address Street],Chr(10))),"")

If the Business Address Street field exists in the view, remove it and add the two new fields (they will be in the “User-defined fields in folder“ group).  Now select all the Contacts in this view and paste them into Excel.  Voila!  No more broken rows.

You can do the same thing for Home Address Street or any other field that may have multiple lines of text.  If you're feeling adventurous, try modifying the formulas to handle the Home/Business Address fields.  These columns can have three or more lines, so it will take some extra effort to get this to work properly, but it is definitely possible.

 

Published Friday, April 08, 2005 2:45 PM by legault
Filed under:

Comments

Saturday, April 09, 2005 5:40 AM by Anonymous

# re: If the columns and rows are messed up when copying items to Excel from an Outlook view...

Eric -

Can't this part of your first fromula be shortened from this

Left([Business Address Street],InStr([Business Address Street],Chr(10)))=""

to this

InStr([Business Address Street],Chr(10))>0

(Just saving a few keystrokes).

- Jon
Wednesday, April 13, 2005 2:56 PM by legault

# re: If the columns and rows are messed up when copying items to Excel from an Outlook view...

If you mean so that it looks like this:

IIf(InStr([Business Address Street],Chr(10))>0,[Business Address Street],Left([Business Address Street],InStr([Business Address Street],Chr(10))-1))

Unfortunately, that doesn't work.
Thursday, December 01, 2005 8:25 AM by Anonymous

# re: If the columns and rows are messed up when copying items to Excel from an Outlook view...

I have tried this and what happens for me is the info for the next line of the address gets dumped into the next row, but now after splitting the address it still goes to the next row but leaves the first column empty. I also have addresses with 4 lines. any ideas? thanks
Wednesday, December 07, 2005 11:48 AM by legault

# re: If the columns and rows are messed up when copying items to Excel from an Outlook view...

Boston: You'll need an additional formula field for each expected line break. Use the example above for the expected second line break as a basis for the subsequent formulas. Post your answer when you have it working!
Wednesday, July 12, 2006 8:06 AM by Anonymous

# re: If the columns and rows are messed up when copying items to Excel from an Outlook view...

Hmmm. I did what you said, but it still doesn't fix the problem. If I view the Contacts in Outlook, they appear as they should (the street address has been divided into two separate fields as you suggested), but when I paste into Excel, it is apparently still "seeing" some sort of line break because the rows continue to appear messed up. Everything after Business Address Street Line 1 is in a second row. Any help would be great.
Wednesday, July 12, 2006 9:18 AM by Anonymous

# re: If the columns and rows are messed up when copying items to Excel from an Outlook view...

OK, I figured it out. I changed the end of your first formula from Chr(10))-1)) to Chr(10))-2)). This fixed the problem.

However, I have some addresses that contain more than two lines of street information. My programming skills are not adequate enough to figure out what each part of your formula actually does. I need to add a third line (and possibly a fourth), but I can't figure it out. Thanks.
Wednesday, July 12, 2006 1:17 PM by Anonymous

# re: If the columns and rows are messed up when copying items to Excel from an Outlook view...

OK. Sorry. I guess I should have tried harder before posting the second time. Anyway, I finally got it. For anyone out there whom this information might help. Here is the code:

Business Address Street Line 2:
IIf(InStr([Business Address Street],Chr(10))>0,Mid([Business Address Street],InStr([Business Address Street],Chr(10))+1,IIf(InStr(InStr([Business Address Street],Chr(10))+1,[Business Address Street],Chr(10))>0,InStr(InStr([Business Address Street],Chr(10))+1,[Business Address Street],Chr(10))-InStr([Business Address Street],Chr(10)),Len([Business Address Street])-InStr([Business Address Street],Chr(10)))),"")

Business Address Street Line 3
IIf(InStr(InStr([Business Address Street],Chr(10))+1,[Business Address Street],Chr(10))>0,Mid([Business Address Street],InStr(InStr([Business Address Street],Chr(10))+1,[Business Address Street],Chr(10))+1,IIf(InStr(InStr(InStr([Business Address Street],Chr(10))+1,[Business Address Street],Chr(10))+1,[Business Address Street],Chr(10))>0,InStr(InStr(InStr([Business Address Street],Chr(10))+1,[Business Address Street],Chr(10))+1,[Business Address Street],Chr(10))-InStr(InStr([Business Address Street],Chr(10))+1,[Business Address Street],Chr(10)),Len([Business Address Street])-InStr(InStr([Business Address Street],Chr(10))+1,[Business Address Street],Chr(10)))),"")

*There may be shorter and simpler code for doing this, but, anyway, this works for me. Thanks for getting me started.
Wednesday, July 12, 2006 1:28 PM by legault

# re: If the columns and rows are messed up when copying items to Excel from an Outlook view...

Wagner: I just tried for about an hour and I can't figure this out. SUPER tricky. This would be easy if we could use the Replace function, but it's not exposed.
Monday, July 17, 2006 1:58 PM by Anonymous

# re: If the columns and rows are messed up when copying items to Excel from an Outlook view...

Yeah...so...surprise, surprise. I was slightly wrong again. Actually, the correct formula for Business Address Street Line 2 is:

IIf(InStr([Business Address Street],Chr(10))>0,Mid([Business Address Street],InStr([Business Address Street],Chr(10))+1,IIf(InStr(InStr([Business Address Street],Chr(10))+1,[Business Address Street],Chr(10))>0,InStr(InStr([Business Address Street],Chr(10))+1,[Business Address Street],Chr(10))-InStr([Business Address Street],Chr(10))-2,Len([Business Address Street])-InStr([Business Address Street],Chr(10)))),"")

And the Business Address Street Line 3 formula can be shortened to:

IIf(InStr(InStr([Business Address Street],Chr(10))+1,[Business Address Street],Chr(10))>0,Mid([Business Address Street],InStr(InStr([Business Address Street],Chr(10))+1,[Business Address Street],Chr(10))+1,Len([Business Address Street])-InStr(InStr([Business Address Street],Chr(10))+1,[Business Address Street],Chr(10))),"")

As of yet, I have discovered no way of creating a fourth line because...well...it's complicated, but basically the formula starts looping back through the Business Address Street string, which results in redundant data being displayed.

It's ok, though. I mean honestly, who is going to have more than a 3-line street address? If so, they should just move to make it easier on the rest of us.
Monday, August 14, 2006 10:00 AM by legault

# re: If the columns and rows are messed up when copying items to Excel from an Outlook view...

Wagner: LOL - I couldn't have said it better myself.
Wednesday, January 21, 2009 10:19 PM by Boxes in my addresses | keyongtech

# Boxes in my addresses | keyongtech

# change the custom fields when export emails to excel | keyongtech

Anonymous comments are disabled