Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Although you can copy and paste data in and out of Excel like you can in almost every other program, Excel lets you take this a step further using its Import and Export features. These features are useful when you have to share data with programs that don't work directly with Excel. Maybe they don't recognize Excel's file format. So let's say we get info from a database and we need to bring that data into this worksheet. We are going to start by importing here into Cell A5. But before we do that I want you to see what the raw data will look like.
I have this file open here in Windows Notepad and you can see the file here as importdata.txt and the first line here, these are our column headers, Last Name, and First Name and so forth and you can look here and you can see we have last names, first names, department and so on. Now we have two of these files in the Chapter 8 folder of the Exercise Files. import data.txt, a text file, and also import data.csv. CSV stands for Comma Separated Values and you can see here these are also separated with commas.
The reason we have two of them is sometimes you'll get data with a TXT extension, sometimes you will get data with a CSV extension, and Excel can treat them slightly differently when you're importing and you'll see that. So I am just going to close this here. So here we are back in Excel and let's go to the Data tab and over here in the left side of the Data tab under the Get External Data group choose From Text. So here in the Chapter 8 folder the Exercise Files, we can see both the CSV and the TXT.
Let's double-click the TXT file and this immediately brings you into the Import Wizard and you can see there are three steps to the Wizard. Now to begin with, you have two choices. Is it Delimited or Fixed Width? Well, we are just talking about Delimited because there are commas separating the values. Fixed Width would use if your original source data was broken up into columns that are the exact same width and separated the exact same amount. That's kind of weird and that's not what this is anyway, so make sure Delimited is selected and click Next. Now this asks us here well, what is the Delimiter? Well as we are talking about, it's commas.
So we want to deselect anything else. Tab is selected here by default, so I am going to deselect that and select commas and as soon as I select Comma, you notice that this is all now separated. So click Next and this allows us to treat the column specially, if we want. So for example if there is a column that maybe we don't want import, we can choose not import it, or if it's a date, we can treat it specially as a date and reformat it as we go. We don't need to do any of that. So click Finish and again this confirms where do we want to start importing the data.
So click OK and boom, it just puts it in. Now notice something here. The first row repeats what we already had in the worksheet, which means you could delete it. But it's a good thing that it's in here because this way we can measure that oh yes, the last name is indeed the last name, the hours is indeed hours, location is location. So we can just remove this Row 5. Put your mouse pointer on the header for Row 5, so you have that backward pointing arrow, right-click and choose Delete.
Now it's gone. Now we have a nice Excel sheet. So let's go save this under a new name. You could either press the F12 key on your keyboard to Save As or go to the File tab and Save As and let's call this payroll with the imported data and Save. Well, I want to show you a second method of bringing in data. So let's just close this. You could press Ctrl+F4 to close or click the Close button over here and we are going to open the text file. So you can press Ctrl+O to open or click the File tab and choose Open.
This is showing us Excel files. It's not shown us those text file. So we want to click this dropdown list over here and we want to choose Text Files and this shows us both the CSV and the TXT. Double-click the TXT and this launches us back into the Wizard. So again make sure it's Delimited. click Next. If any other Delimiters are selected, you want to deselect and make sure a comma is the only one selected. Click Next, click Finish and there it is and it opens right up and we have our column headers and then we can format it.
We can just close it without saving again. Press Ctrl+F4 to close or click here at the Close button here. Now let's open the CSV. Here is where CSV and the TXT are a little different. Again I will just press Ctrl+O to open. Here's the CSV. Remember, we're looking at Text Files not Excel files. Double-click CSV. And boom, it just opens. No wizard, no nothing. It just brings it right up onto the screen. Okay, that's all for importing. Let's talk a little bit about exporting. Exporting a worksheet takes even fewer steps. we don't have to go through a wizard.
Let's open up the file in Chapter 8 of the Exercise Files. You will probably need to click this drop-down over here and choose All Excel Files. Let's open up the file called Export this. So here we have a pretty typical Excel sheet but we have to modify this here la ittle bit because when we export to CSV, we need to make sure we're only exporting alphanumeric values. Numbers are okay, text is okay, any formatting will be wiped out because text files including CSV files don't support formatting. But we have these graphics here.
We have this Sales thing here that's formatted that's above our column headers. That's no good. We also have here some functions. We have these calculations and we can't export that either. So we need to remove them. The problem is this is a worksheet we really might need to use. So there is kind of a danger if you start deleting parts of this worksheet. It's very easy to save over it and then you have lost some of your data. So my advice is whatever you're doing a process like this, save it under a temporary file name so that way you don't have to worry about messing it up.
So you could either press F12 to Save As or go to the File menu and Save As. And I always save these kind of temporary files as delete. That is I literally call them delete, so that I know I could go back later and delete them without any worries. Save. So let's click this graphic and Delete, click on the edge of this graphic and Delete. And let's delete the first three rows. Put your mouse pointer on the header of where I want, drag down so you have the headers of Rows 1, 2, 3 selected, and right-click the mouse and choose Delete and the same for the Total row.
Right-click the header here of the Total row and press Delete. One more thing we have to do is these numbers here have column headers but we don't have a column header here for our description. We really should put that in. So you could simply click up there and type products. And don't worry that it doesn't have the same formatting as the other columns, because the formatting is going to go away anyway. So now we are going to go and export this and if you want to save over it, press Ctrl+S or press or click the Save button. That's okay.
So here is how we can go and make this a CSV file. Go to the File tab, go do down here to Save & Send, click over here, Change File Type and now you can go over here and choose CSV and Save As. Now that's a lot of work. Let me show you an easier way to do that. I am just going to escape out, so we are back here at the Data tab. All you have to do is a regular old Save As. So you could go to the File tab and Save As or press the F12 key to Save As and then just click over here where it says File Type and now we can choose Comma Separated Values. I think it's a lot easier way to do it and let's just call this product data and click Save.
Now this is giving us a warning that there are parts of this file that are not compatible with CSV because we have all that formatting. That's perfectly fine. Click Yes and there we are now. We can see this product data.csv. So these are features that you might want to use whenever you need to share data between Excel and another program that normally don't talk to each other.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98152 Viewers
80 Video lessons · 141355 Viewers
59 Video lessons · 59702 Viewers
52 Video lessons · 72929 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.