Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Limiting text length with formulas

From: Excel 2010: Data Validation in Depth

Video: Limiting text length with formulas

In column A of this worksheet called Text Formulas, there is a data validation rule that ensures that the Social Security Numbers are always nine characters long. That number must be that length; it can't be any more or any fewer. And that's just fine. It works great here. Notice that there's no formatting that exists here. That probably should be applied, but that is a different issue. So I'm going to put in a Social Security Number, and probably no one would ever type one like this, but you certainly could. This has nine characters, but note that it does have a letter in it.

Limiting text length with formulas

In column A of this worksheet called Text Formulas, there is a data validation rule that ensures that the Social Security Numbers are always nine characters long. That number must be that length; it can't be any more or any fewer. And that's just fine. It works great here. Notice that there's no formatting that exists here. That probably should be applied, but that is a different issue. So I'm going to put in a Social Security Number, and probably no one would ever type one like this, but you certainly could. This has nine characters, but note that it does have a letter in it.

And here and there someone might see an I or zero and somehow think that might occur there, and you could certainly imagine certain kinds of code numbers where maybe it's not clear that they should be numerical, but here it is. And the data validation rule as it exists doesn't work right now. So let's change it and make sure that the entry is numerical. The data validation rule that we already have is in place, and here it is, and it's all about the Text length. If we want to use other criteria along with this, we have to change the choice here to be Custom, meaning custom formula, and there are two things we want to do here.

We want to retain this idea, so we need the And function, = And, and then the two criteria within this will be, first of all, the one related to length. You might or might not know there is a function called LEN, meaning length. You want to be sure that the length of these entries--and we'll use A1; it acts as a substitute for all cells in column A--we want to be sure that the length of A1 equals 9. That's one of our two criteria. And the other one is that we want make sure that this is a number. And sure enough, there's a function called ISNUMBER.

We want to make sure that A1 is a number. Both criteria we want to be true here. Click OK. Now data validation doesn't alter existing entries, so that's still incorrect, and we would change it manually. But let's just test this out a little bit. Let's put in something like that B entered. 9 characters, but it doesn't work. Now because we have a new data validation rule and just revisit that briefly here back to Data Validation to show it again.

Two criteria: the length must be 9 and the entry must be a number. Now you could have another kind of code, something along the lines of what you might be seeing in column B. This might be three characters, four characters, five characters, whatever. But let's say that the rule here is that this must begin with a number. And the first one does, the second one doesn't. A little bit of background in text functions might help here, and so if you had this kind of need, you might know an easy function to use is called Left.

There is a similar function called Right. This simply allows us to look at a cell and to extract the left character-- that would be 1--the two leftmost characters, a 2, and so on. So the leftmost character here, sure enough, is a 2, and if we copy the formula down to here, it's a T. Now, is this a number? Here's a function called--which we just saw--NUMBER. Is this a number? Well, it looks like a number to me.

This one doesn't; that seems to be doing the right thing, but this doesn't, so that might throw you a little bit. There is another function we need here, and it's called VALUE, and so we want to take the value of this. Is that a number? Yes, it is. So backtracking a little bit, we want to create a data validation rule here that makes sure that the leftmost character is a number, so a data validation rule here and here, too, a custom function. Equal. We want to be focused on only the leftmost character here, so L-E-F-T the left character. And once again, we use the active cell as a substitute for all the other ones. Comma 1, that means the first character only.

We want to be sure that that is a number, but we want to be looking at the value of that leftmost character. And often when you do these, of course, it's really to make a mistake regarding how many parentheses we need here. There we go. I think that looks right. Sometimes when you click OK here, you are warned that your formula is incorrect, but it could be syntactically correct and logically wrong. In this case, the syntax is correct.

Once again, existing entries are not altered. Let's see if this works. 4, 5, 6, of course that should work. And, by the way, this doesn't have any restriction of length just yet--maybe we'll do that later--but that's in place and that seems to be okay. But how about those that begin with a letter? That one is not acceptable. And as always, we might consider changing the error alert to explain what's going on. So the more you know about various Excel functions, the more likely you are to expand your use of data-validation type formulas, and in this example here, we saw how it was used to control various text-length types of entries.

Show transcript

This video is part of

Image for Excel 2010: Data Validation in Depth
Excel 2010: Data Validation in Depth

17 video lessons · 9583 viewers

Dennis Taylor
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Excel 2010: Data Validation in Depth.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.