Setting date limitation formulas
Video: Setting date limitation formulasIn this worksheet, data validation rules in columns C require that all the dates occur in the year 2011. Column D doesn't have any rules yet, but in putting in the shipping dates for the items that have been ordered, we are going to make sure, first of all, that the shipping date is later than the order date. Now depending upon the environment of course, you might want to set up a rule to make sure that the shipping date is equal to or greater than the order date. But what if in this environment that the items being ordered require some assembly and packaging, and shipping cannot occur within a two-day time frame? In other words, it has to be more than two days later.
Viewers: in countries Watching now:
In Excel 2010: Data Validation in Depth, author Dennis Taylor shows how to use the data validation tools in Excel to control how users can input data into workbooks and ensure data is entered consistently and accurately. The course covers creating dropdown lists, preventing duplicate entries, and controlling the format of numeric data, dates and times, and text entered into worksheets. Exercise files are included with the course.
- Testing for whole numbers and decimals
- Using the input message box
- Sequencing and placing lists
- Creating multi-tiered lists
- Setting date and time limitations
- Limiting text length
- Locating data validation rules
Setting date limitation formulas
In this worksheet, data validation rules in columns C require that all the dates occur in the year 2011. Column D doesn't have any rules yet, but in putting in the shipping dates for the items that have been ordered, we are going to make sure, first of all, that the shipping date is later than the order date. Now depending upon the environment of course, you might want to set up a rule to make sure that the shipping date is equal to or greater than the order date. But what if in this environment that the items being ordered require some assembly and packaging, and shipping cannot occur within a two-day time frame? In other words, it has to be more than two days later.
We want to make sure that the entries in column D are more than two days later. In this case, maybe we don't want to restrict these to the year 2011 because toward the end of the year some of the items might be shipped in the later year. So clicking column D here and setting up data validation, the first thought might be, as you look at the dialog box, that the validation criteria we are trying to set up here involves using probably a Date criterion, but it is not; it is going to be Custom-- actually a custom formula.
And the formula will involve using the active cell. Now, I did select column D, and I highlighted cells starting in D2. We probably see D2 as the active cell. See, in the upper-left corner here, to the left of the Formula bar, but we are seeing D1 right now, so we will use this in the formula. The formula here is not so obvious, but once you see it, it will start to make some sense. = D1>C1+2. Now although literally we don't see the meaning here, what this means is any entry in column D must be more than two days greater than the entry in column C. And so even though we are not using D1 and C1, the formula involves those two cells.
So when we click OK here, sometimes it is a little startling at first when you see this message, and it simply means the D1 and C1 don't fit our little formula. Do we want to continue? Yes, we do. So, simple test here. How about the 5th, 1/5/11, the 5th of January? Why is that wrong? Our formula indicates the shipping date must be more than 2 days, not 2 days, but more than 2 days later. We will do a retry and we will make this 6, for example. How's that looking? Fine, so we can put in any date here that's more than two days later than the order date.
For every single cell here, the comparison is made with the cell to its left. Now what if we are making adjustments here and we put in a different date? I am going to put in an 8 here for the shipping date. Then this thought might occur to you: what if one of the dates that you put in here is a Sunday? Maybe you don't do shipping on Sundays. Is that a Sunday? Or maybe don't do shipping on Saturdays. Let's also screen out those kinds of entries as well. Now, you may or may not be familiar with this function, =weekday, an Excel function.
And in looking at a date, it will tell us the day of the week--not initially in a very meaningful way. It gives us a value. 7 does mean Saturday. 1 means Sunday and so on. So if we don't want entries for the weekday is equal to 7 or 1, that would be Saturday or Sunday, we can screen out those as well. So what I would like to do here is prepare this formula outside of, although you can certainly do it with inside, data validation. Let me just copy it in. So I would like to use this function here along with the current restriction that the shipping date being more than two days greater than the order date, and so the function will read something like this. And, meaning we have got two criteria we want to set up here.
The first one we already wrote, but I will write it again, and D1. Don't really have to capitalize, but it is easier to see this way. D1>C1+2, and weekday of D1<>1, meaning Sunday, and another one of these. And I will just copy this and paste it and change it slightly. Ctrl+C here, click right here, Ctrl+V, 7. Now the formula is not going to stay into this cell.
I am just typing it here so you can see it more clearly. And here's the formula that we are about to use as a validation formula. And in English, it reads as follows. In column D, every entry must be more than two days larger than the corresponding entry in column C, and the weekday of the entry in column D cannot be equal to 1--that's Sunday; can't be a Sunday--and it cannot be equal to 7, which is Saturday. So all of this here is going to be the validation formula.
You don't necessarily need to prepare it this way. You can do this within the data validation dialog boxes, which is what we are about to do. But here all I am doing is highlighting this and copying with Ctrl+C, and I might want to leave it here for a moment for documentation, so I will just put in a space and press Enter. Go back to Data Validation. Click column D > Data Validation, and instead of this rule, I'm simply going to press Ctrl+V here to paste in the formula that I just had displayed earlier.
Sometimes when you look at these, they are a little clipped off. I am going to drag leftwards so we can see it all. It looks a little funny at times. So there is that same formula, which all this could have been prepared within here. Click OK. Now the existing date that's there will not change. Data validation doesn't do anything with existing data; it is the new data that it is going to react to. Once again, we get this kind of a message, simply meaning that cells D1 and C1 don't fit our rules. We do want to continue anyway. So as an example here, I'll try and change this to the 9th.
That's a Sunday. And we see that it doesn't work. Now ideally, what we should do here to accompany all this--and that was shown in previous movies--going back to Data Validation, provide either an input message that describes the dates cannot be Saturdays and Sundays, or possibly and create an error alert message that explains why an entry is incorrect. You don't necessarily need to do those, but it's helpful to explain to some people what went wrong. So on a different entry here and I'll just type in a date here, 1/8/11.
That's a Saturday and we get the same message. And of course a correct entry here looks like 7 is going to work there. Here we go. That's a Friday. That's just fine. So you get the idea. The more you know about Excel functions, the more inclined you are likely be to use more sophisticated approaches to controlling data. So column D from now on has entries that have to meet all three of the criteria that we set up in this data validation formula.
There are currently no FAQs about Excel 2010: Data Validation in Depth.