Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Extra spaces in data many times don't cause major problems, but occasionally they do. And it's increasingly a problem in these days of downloading data. In this particular worksheet here you might notice already here in cell C5 there are some extra spaces between the two words. That's probably not going to be a problem. But what happens if we sort this data? I want to click somewhere in column C here. Any cell could have stayed there. I'm going to click A-Z. The entire list is going to be sorted. And what do we see here? This ends up first.
It's got some leading spaces. This does too. We're not counting them exactly, but we see this. We scroll down a little bit, it looks like maybe we've got a few these. In fact, this list doesn't look like it has sorted at all, does it? And then eventually we see, oh yes, here it is. What's happening here? Notice if you look closely from this cell upward everything has at least one leading space. My zoom factor right now is 130%. A lot of us work at 100% or even lower if we have lots of data.
Those leading spaces do not always jump out at you, but they certainly emerge when you sort the data, as in this case here. So how do we clean this up without re -keying or retyping any of the data? Typically, in situations like this, what you need to do is to temporarily put in a new column. So I'm simply going to right-click on column D here, Insert, and what are we do here? We use a function called Trim. And that essentially does three things to data. It will remove leading spaces, which can be a big problem, particularly in sorting.
Trailing spaces, usually not a major issue, and also multiple inner spaces, as an example in row 4 there, between Quality and Assurance. Multiple consecutive inner spaces get reduced to one space. So we'll simply Enter here, and double- click to copy this down the column using one of our top ten tricks, and that data looks pretty good. And you can see what's happening here with those multiple inner spaces. And you can see the difference here. The leading spaces are gone. Now, trailing spaces, I didn't put any em, but I am going to put one in here on purpose.
You don't see those very readily, and we don't see any difference over here at that end of it, but those are taken care of as well. So once we've this in place, the next thing to do after we put in the formula here is use another one of our top ten tricks and simply copy this and paste it all in one action into column C. So with the right mouse button drag any edge here on top of the old data, and as we let go the right mouse button, Copy Here as Values Only.
And then get rid of this column. And now we can click in column C, do our A-Z Sort, and things will be in the appropriate order. There is another issue with spaces as well. I want to make column F a bit wider here, because there are some formulas here. And this formula in English says, IF your status in Full Time and your job rating, which for the moment we can't see, is >3. You get a $1000, otherwise nothing. We make that column a bit narrower with there. There we are. We can just see that Job Rating out there.
So in the first case here it's a Contract person, so automatically that person doesn't get the bonus. We'll stick around on the Full Time people here that does have the appropriate rating. For example, right here. But what if the Status entry here had a trailing space? Now, the trailing space you wouldn't see. It wouldn't emerge if you were sorting, but it certainly pops up here. Why didn't this person get the bonus? This person has a Full Time Status, as well as a Job Rating of 5, and if it is greater than 3, combination of both, but it's not happening.
So what might we do here? Probably what we did with column C, but if we don't have the time to do that or if you want to cover all bases here, another way to approach this is to simply use the Trim function right here. We want to say IF this cell here is equal to Full Time, why don't we look at the trim version of this? And we would do this for the entire column possibly. The trim version of E10. If that's equal to Full Time and the Job Rating is above 3, we'll give these people a $1000 dollars.
So that takes care of that issue, and we would then copy this downward by double-clicking and then drag it upward. I think the better long term approach is to clean up the entire column first, but you can also do this on the fly. And maybe this data is being used by another worksheet or another user who refers to this, and we really can't make a change to it. This is a workaround here. Again, using the Trim function, which is great for cleaning up data. It gets rid of leading spaces, trailing spaces, and multiple inner spaces get reduced to one.
Get unlimited access to all courses for just $25/month.Become a member
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.
Your file was successfully uploaded.