Managing leading zeroes in zip, numerical, and text codes
Video: Managing leading zeroes in zip, numerical, and text codesIf you use numeric codes that begin with zeros--and of course some ZIP codes do begin with zero-- you need to be able to see and retain those zeros. There are a couple techniques we want to take a look at there. First of all, in Column A, let's imagine that someone typed the ZIP codes, maybe looking at a sheet of paper, heads down, just typing the zeros where appropriate, but the zeros actually didn't appear. So you can imagine, in Cell A5, for example, whoever was typing this probably typed 02299, as I'm typing here. So what happens though when we press Enter? The zero doesn't appear there.
- Next steps
Viewers: in countries Watching now:
In this course, Dennis Taylor explores the functions, commands, and techniques in Excel that restructure data, remove unwanted characters, convert date data into the desired format, and prepare data for efficient analysis. This course helps get data from a business management system file, other database software, a text file, or a poorly designed Excel worksheet into optimal shape for working with in Excel.
- Moving or inserting rows and columns of data with a simple drag
- Using Text to Columns
- Harnessing the Find and Replace command to replace data at the character level
- Dealing with special characters and wildcards during search
- Converting dates with text functions
- Converting text data to values/numbers
- Checking and correcting spelling mistakes
- Splitting data into multiple columns via the Text to Columns feature
- Combining data from different columns via concatenation
Managing leading zeroes in zip, numerical, and text codes
If you use numeric codes that begin with zeros--and of course some ZIP codes do begin with zero-- you need to be able to see and retain those zeros. There are a couple techniques we want to take a look at there. First of all, in Column A, let's imagine that someone typed the ZIP codes, maybe looking at a sheet of paper, heads down, just typing the zeros where appropriate, but the zeros actually didn't appear. So you can imagine, in Cell A5, for example, whoever was typing this probably typed 02299, as I'm typing here. So what happens though when we press Enter? The zero doesn't appear there.
Now we wouldn't have to go through any shenanigans or anything unusual here; simply format Column A--right- click > Format Cells. And ideally, you do this before you put the data in--it makes a bit more sense--and you'll see correct entries as we go. There is a special category on the Number tab in Format Cells. It's called Special. And we got two ZIP code entries: Zip Code, the standard five digit, or the Zip Code + 4. In this case, just Zip Code. There we go, click OK. And the zeros are in place.
So in situations like that, for example suppose this ZIP code here needs to be changed and it's 00123, we'll just type 123, and the zeros pop into place automatically. So that's an easy fix. Now at other times we have situations like we see in columns C and D. Let's imagine that these ID numbers here, too, need to have leading zeros. Now everything in Column C is actually a number as it turns out, and here, too, we possibly could have been typing in leading zeros and then look up and see what's going on. But we need to make some adjustments here. And as we look at some of the numbers, recognize some are three digit, four digit, five digit.
We actually want to turn these into six-character ID numbers. So what we're seeing in Column D is actually what we want to have happen. So let's actually shows how this is set up. What we need to do here is to type in, in this particular example here, a function called =text. And we want to take the data from C2, comma. The text function requires that we give this a format, and the format is going to be within double quotes, six zeros.
Now the zeros, think of them sort of as placeholders that will contain values, and if there's no real value to be picked up, we'll see a leading zero, or zeros, as necessary. So six zeros, double quote and we don't need the right parenthesis here since it is just a single set, and we see what's happening. Copy this down the column. Now the others were already done anyway, but at least we see how that looks, and here's the function again. And you see what's happening. For example, in C5, the 814 now has three leading zeros.
So you can imagine some variations on how to use that as well. In Column F, a different situation. The code numbers here are a mix of letters and numbers, and we want them to turn into nine characters and have leading zeros. Here it's a little bit different, and what we want to do here is to use a function called rept, which means repeat. And what we would like to do is put in some leading zeros, so the symbol we want to put in, within double quotes, is a zero.
Now the question is, how many times do we want to put it in there? And look at the different entries in Column F. The first entry in Cell F2 is six characters long, the next one is seven, the next one after that looks like it's nine, and so on; it varies. So the total length here is 9. How many zeros do we need to put in here in cell F2? We need to put in 3. So, how do we figure that out? We want the number 9 minus the existing length. 9- and here is a function called len, meaning length.
So the length of F2 right now in this example is 6. So what we're about to say here--we're not finished with the formula just yet-- we want to take this zero character and put it in here in the first case three times. 9 minus the length of F2, which is 6. So we're going to put three leading zeros there, and then what are we going to put in? The ampersand means "and," the actual content of F2. There we are.
And we see what's happening and double- click, copy this down the column. And it had been set up again anyway, but just take any of these at random, take a look at them--for example, this one here. As we're looking at this, once again, in all cases here, the length is going to, well, here and there, vary. The length here is 5. 9-5 is 4. So how many leading zeros do we want here? Four leading zeros. So in these situations here in Column G, we're dealing with data that's a mix of numbers and texts.
Over in column D, we're dealing with all values. So there is a difference in how these are set up. But these are all using various text functions that allow us to take data that's not in the best of shape and turn it into the format that we would like. It's not always directly done by using the Format command, as you've seen in these examples here. Those are some great tools for cleaning up data and turning it into the appearance and the content that you want. Here, too, as in a lot of other examples, if we want to keep the results here, we would select all of this data, and it could be thousands and thousands of entries, possibly it might be better even to pick the column in that example.
We could adjust the headings later and simply with the right mouse button, drag this on top of Column F, let go, Copy Here as Values Only. Change your headings. We're all set. Get rid of this.
Find answers to the most frequently asked questions about Cleaning Up Your Excel 2010 Data .
Here are the FAQs that matched your search "" :
- Q: Where can I learn more about Excel formulas?
- A: Discover more on this topic by visiting Excel formulas on lynda.com.
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.