Home > Books > 100 Top Tips: Microsoft Excel > Creating custom validation

Tutorial: Creating custom validation in Excel

If your spreadsheet stores unusual data formats, such as product codes, you can use the Data Validation rules in Excel to create your own custom validation rules. Discover how to create custom rules for Data Validation in this Microsoft Excel tutorial by Sean McManus, from the book 100 Top Tips: Microsoft Excel

You can write your own validation rules for an Excel spreadsheet. Select the cell(s) you want to validate and go to the Data Validation options (see Tip 7). Select Custom in the Allow menu. In the Formula box, enter a formula that gives a result of TRUE or FALSE. Here are some examples to validate cell J8:

  • Must start with text "CPC".
    =COUNTIF(J8, "CPC*")=1

  • Length must be 3.

  • Must be a number.

  • First character must be a number. The LEFT function is used to extract the character, and ISNUMBER is used to test whether it is a number. The VALUE function is required because in a data item like "UK-52", the 52 would otherwise be treated as text.

  • Last character must not be a number. To see whether a character is not a number, we can check whether it is a number, and then wrap it in the NOT function to reverse the result.

  • Must be unique in column J. This shows an error if the same data has already been entered in the same column.
    =COUNTIF(J:J, J8)<=1

  • Must be odd. (ISEVEN can be used, too.)

To allow multiple options, join them with OR, like this example, which allows data of 3 or 5 characters to be valid:
=OR(LEN(J8)=3, LEN(J8)=5)

To enforce multiple validation rules, use AND, like this example, which requires a 3-character code starting with A:
=AND(LEN(J8)=3, COUNTIF(J8, "A*")=1)

Where next?

About 100 Top Tips: Microsoft Excel

This tutorial is from 100 Top Tips: Microsoft Excel. The powerful pocketbook helps you to learn more from your data, be more productive with Excel, and improve the accuracy of your spreadsheets. It's packed with shortcuts, tips, and hacks for Excel that solve everyday business problems. Find out more and download a free PDF sampler here, and order the book online here.

Book cover: 100 Top Tips: Microsoft Excel

Buy the book here


© Sean McManus. All rights reserved.

Visit www.sean.co.uk for free chapters from Sean's coding books (including Mission Python, Scratch Programming in Easy Steps and Coder Academy) and more!

Discover my latest books

Coding Compendium

Coding Compendium

A free 100-page ebook collecting my projects and tutorials for Raspberry Pi, micro:bit, Scratch and Python. Simply join my newsletter to download it.

Web Design in Easy Steps

Web Design IES

Web Design in Easy Steps, now in its 7th Edition, shows you how to make effective websites that work on any device.

100 Top Tips: Microsoft Excel

100 Top Tips: Microsoft Excel

Power up your Microsoft Excel skills with this powerful pocket-sized book of tips that will save you time and help you learn more from your spreadsheets.

Scratch Programming in Easy Steps

Scratch Programming IES

This book, now fully updated for Scratch 3, will take you from the basics of the Scratch language into the depths of its more advanced features. A great way to start programming.

Mission Python book

Mission Python

Code a space adventure game in this Python programming book published by No Starch Press.

Cool Scratch Projects in Easy Steps book

Cool Scratch Projects in Easy Steps

Discover how to make 3D games, create mazes, build a drum machine, make a game with cartoon animals and more!

Walking astronaut from Mission Python book Top | Search | Help | Privacy | Access Keys | Contact me
Home | Newsletter | Blog | Copywriting Services | Books | Free book chapters | Articles | Music | Photos | Games | Shop | About