Preparing the text file prior to importing to Excel

%3CLINGO-SUB%20id%3D%22lingo-sub-1316532%22%20slang%3D%22en-US%22%3EPreparing%20the%20text%20file%20prior%20to%20importing%20to%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1316532%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20trying%20to%20get%20data%20from%20a%20text%20file%20into%20Excel.%26nbsp%3B%20How%20would%20I%20go%20about%20getting%20the%20data%20from%20the%20text%20file%20that%20is%20listed%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECompany%3C%2FP%3E%3CP%3Eaddress%3C%2FP%3E%3CP%3EPhone%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECompany%3C%2FP%3E%3CP%3Eaddress%3C%2FP%3E%3CP%3Ephone%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eand%20so%20on......%26nbsp%3B%20There%20could%20be%2020-50%20or%20more%20companies%20listed%20vertically%20like%20that%20on%20a%20text%20page.%3C%2FP%3E%3CP%3EI'd%20like%20to%20get%20that%20data%20into%20an%20Excel%20Spreadsheet%20with%20headers%20for%20Column%20A%2C%20B%2C%20and%20C%20to%20be%3C%2FP%3E%3CP%3Efor%20%22Company%22%2C%20%22address%22%2C%20and%20%22phone%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWithout%20having%20to%20rearrange%20manually%20and%20all%20the%20copy%20and%20pasting%2C%20is%20there%20a%20short%20cut%20of%20some%20sort%20by%20perhaps%20adding%20characters%20at%20the%20end%20of%20each%20line%2C%20setting%20up%20a%20formula%2C%20etc%20so%20that%20the%20import%20will%20place%20each%20line%20of%20data%20in%20its%20appropriate%20place%20in%20the%20Excel%20Spreadsheet%3F%26nbsp%3B%20I've%20attached%20a%20screen%20shot%20of%20the%20Excel%20spreadsheet%20and%20the%20text%20file%20showing%20the%20content%20and%20how%20it%20appears.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1316532%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%20on%20Mac%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1317676%22%20slang%3D%22en-US%22%3ERe%3A%20Preparing%20the%20text%20file%20prior%20to%20importing%20to%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1317676%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F626602%22%20target%3D%22_blank%22%3E%40Jerry_Snell%3C%2FA%3E%26nbsp%3BYour%20data%20seems%20to%20be%20consistently%20structured.%203%20fields%2C%20blank%2C%203%20fields%2C%20blank%20etc.%3C%2FP%3E%3CP%3EThat%20makes%20it%20relatively%20easy.%20I%20have%20attached%20a%20small%20example%20with%20the%20raw%20data%20in%20Sheet1%20and%20the%20transposed%20data%20in%20Sheet2%2C%20using%20two%20different%20methods.%20The%20first%20will%20work%20if%20you%20are%20on%20the%20most%20recent%20version%20of%20Excel%20as%20it%20uses%20the%20TRANSPOSE%20function.%20The%20second%20uses%20OFFSET%20and%20should%20always%20work.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1319917%22%20slang%3D%22en-US%22%3ERe%3A%20Preparing%20the%20text%20file%20prior%20to%20importing%20to%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1319917%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20was%20very%20helpful!%26nbsp%3B%20Thank%20you.%26nbsp%3B%20I%20used%20the%20OFFSET%20method%20and%20it%20worked%20great.%26nbsp%3B%20One%20follow%20up%20question%3A%26nbsp%3B%20In%20sheet%202%20of%20the%20attached%2C%20how%20would%20I%20then%20separate%20the%20city%2C%20state%20and%20zip%20into%203%20new%20columns%20to%20the%20right%20and%20have%20the%20phone%20being%20the%20last%20column%3F%26nbsp%3B%20%26nbsp%3B%20(as%20shown%20with%20headers%20in%20sheet%203)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1320223%22%20slang%3D%22en-US%22%3ERe%3A%20Preparing%20the%20text%20file%20prior%20to%20importing%20to%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1320223%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F626602%22%20target%3D%22_blank%22%3E%40Jerry_Snell%3C%2FA%3E%26nbsp%3BStart%20by%20inserting%20three%20three%20columns%20in%20Sheet%202%2C%20Copy%20all%20and%20Paste%20as%20Values%20in%20Sheet3%20(step%201).%20Next%2C%20you%20use%20Text-to-Columns%20(on%20the%20Data%20ribbon)%20to%20split%20the%20address%20in%20%3CSTRONG%3Ethree%3C%2FSTRONG%3E%20columns%2C%20using%20the%20comma%20as%20the%20delimiter%20(step%202).%20Without%20changing%20any%20of%20the%20settings%2C%20this%20creates%20separate%20columns%20for%20%26nbsp%3Bthe%20Address%2C%20City%20and%20%22%20State%20ZIP%22.%20Next%2C%20perform%20a%20similar%20action%20on%20the%20State%20column%2C%20but%20now%20using%20space%20as%20the%20delimiter.%20Notice%20that%20this%20wants%20to%20create%20%3CSTRONG%3Ethree%3C%2FSTRONG%3E%20columns%20again.%20One%20blank%20column%20(because%20of%20the%20space%20before%20the%20State%20code)%2C%20one%20for%20the%20State%20and%20one%20for%20the%20ZIP.%20Before%20pressing%20Finish%2C%20select%20the%20first%20column%20in%20the%20preview%20window%20and%20have%20Excel%20%22Skip%22%20the%20first%20column!%20The%20two%20other%20columns%20can%20remain%20General%20(step%203).%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screenshot%202020-04-20%20at%2006.15.17.png%22%20style%3D%22width%3A%20216px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F185266i8681AAEF83B25E9C%2Fimage-dimensions%2F216x202%3Fv%3D1.0%22%20width%3D%22216%22%20height%3D%22202%22%20title%3D%22Screenshot%202020-04-20%20at%2006.15.17.png%22%20alt%3D%22Screenshot%202020-04-20%20at%2006.15.17.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3ENow%2C%20this%20is%20all%20very%20easy%20and%20doesn't%20take%20more%20than%20two%20minutes%20to%20set-up%20and%20execute.%20If%20this%20is%20a%20one-time%20task%2C%20it%20will%20work%20perfectly.%20However%2C%20if%20you%20would%20have%20to%20do%20this%20frequently%2C%20on%20large%20and%20%22dirty%22%20data%20sets%20and%20with%20more%20complex%20rules%20for%20cleaning%20the%20data%20and%20splitting%20columns%2C%20you%20might%20want%20to%20invest%20some%20time%20learning%20how%20to%20use%20%22Get%26amp%3BTransform%22%20a.k.a.%20%22Power%20Query%22%2C%20provided%20you%20have%20access%20to%20a%20PC%20version%20of%20Excel.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20attach%20a%20file%20containing%20the%20outcome%20of%20every%20step%20described%20above%20in%20Sheet3.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1321691%22%20slang%3D%22en-US%22%3ERe%3A%20Preparing%20the%20text%20file%20prior%20to%20importing%20to%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1321691%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20was%20able%20to%20get%20step%201%20done%20but%20when%20I'm%20performing%20the%20%22text%20to%20columns%22%20for%20step%202%2C%20it's%20showing%20up%20as%20the%20formulas%20in%20the%20columns%20instead%20of%20the%20actual%20data.%26nbsp%3B%20Any%20idea%20on%20what%20I'm%20missing%3F%3C%2FP%3E%3CP%3ESee%20the%20screenshot.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1321793%22%20slang%3D%22en-US%22%3ERe%3A%20Preparing%20the%20text%20file%20prior%20to%20importing%20to%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1321793%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F626602%22%20target%3D%22_blank%22%3E%40Jerry_Snell%3C%2FA%3E%26nbsp%3BI%20suspect%20you%20did%20a%20copy%20%2F%20paste%20in%20stead%20of%20copy%20%2F%20%3CSTRONG%3Epaste%20values.%3C%2FSTRONG%3E%20Hence%2C%26nbsp%3BText-to-columns%20split%20the%20formulae%20where%20it%20found%20a%20comma.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1321882%22%20slang%3D%22en-US%22%3ERe%3A%20Preparing%20the%20text%20file%20prior%20to%20importing%20to%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1321882%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20was%20it.%26nbsp%3B%20Thank%20you%20so%20much!!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

I'm trying to get data from a text file into Excel.  How would I go about getting the data from the text file that is listed like this:

 

Company

address

Phone

 

Company

address

phone

 

and so on......  There could be 20-50 or more companies listed vertically like that on a text page.

I'd like to get that data into an Excel Spreadsheet with headers for Column A, B, and C to be

for "Company", "address", and "phone".

 

Without having to rearrange manually and all the copy and pasting, is there a short cut of some sort by perhaps adding characters at the end of each line, setting up a formula, etc so that the import will place each line of data in its appropriate place in the Excel Spreadsheet?  I've attached a screen shot of the Excel spreadsheet and the text file showing the content and how it appears.

6 Replies
Highlighted

@Jerry_Snell Your data seems to be consistently structured. 3 fields, blank, 3 fields, blank etc.

That makes it relatively easy. I have attached a small example with the raw data in Sheet1 and the transposed data in Sheet2, using two different methods. The first will work if you are on the most recent version of Excel as it uses the TRANSPOSE function. The second uses OFFSET and should always work.

 

Highlighted

@Riny_van_Eekelen 

 

That was very helpful!  Thank you.  I used the OFFSET method and it worked great.  One follow up question:  In sheet 2 of the attached, how would I then separate the city, state and zip into 3 new columns to the right and have the phone being the last column?    (as shown with headers in sheet 3)

Highlighted

@Jerry_Snell Start by inserting three three columns in Sheet 2, Copy all and Paste as Values in Sheet3 (step 1). Next, you use Text-to-Columns (on the Data ribbon) to split the address in three columns, using the comma as the delimiter (step 2). Without changing any of the settings, this creates separate columns for  the Address, City and " State ZIP". Next, perform a similar action on the State column, but now using space as the delimiter. Notice that this wants to create three columns again. One blank column (because of the space before the State code), one for the State and one for the ZIP. Before pressing Finish, select the first column in the preview window and have Excel "Skip" the first column! The two other columns can remain General (step 3).

Screenshot 2020-04-20 at 06.15.17.png

Now, this is all very easy and doesn't take more than two minutes to set-up and execute. If this is a one-time task, it will work perfectly. However, if you would have to do this frequently, on large and "dirty" data sets and with more complex rules for cleaning the data and splitting columns, you might want to invest some time learning how to use "Get&Transform" a.k.a. "Power Query", provided you have access to a PC version of Excel.

 

I attach a file containing the outcome of every step described above in Sheet3.

 

 

 

Highlighted

@Riny_van_Eekelen 

I was able to get step 1 done but when I'm performing the "text to columns" for step 2, it's showing up as the formulas in the columns instead of the actual data.  Any idea on what I'm missing?

See the screenshot.

Highlighted

@Jerry_Snell I suspect you did a copy / paste in stead of copy / paste values. Hence, Text-to-columns split the formulae where it found a comma.

 

Highlighted

@Riny_van_Eekelen 

 

That was it.  Thank you so much!!