Cell validation with limits and multiple formulas

sandyandy5

New Member
Joined
May 24, 2022
Messages
35
Office Version
  1. 365
Platform
  1. Windows
Hi! First time poster disclaimer to start with!
I’m creating a nursing shift roster and wanting to limit only 2 ‘D’ shifts per day then to lock others out. I dont know what formula I should be putting into the custom cell validation to achieve this. My current formula is =SUMPRODUCT(COUNTIF(D$4:D$16, Vailid!$E$2:$E$168)).
Any help or ideas of how to make this work would be greatly appreciated!cheers
 
After fixing the helper table formula, did you copy that formula across the top of the table and then pull everything down to the bottom so that the revised formula is populating the entire table? I've examined the last formula you posted and do not see any issues:
Excel Formula:
=IFERROR( INDEX(IF(NOT(
      IF( COUNTIF(Roster!D$4:D$16,"D") >=2,  ($A$2:$A$18="D") )  +
      IF( COUNTIF(Roster!D$4:D$16,"E")  >=2,  ($A$2:$A$18="E") )  +
      IF( COUNTIF(Roster!D$4:D$16,"N") >=2,  ($A$2:$A$18="N") )),
                                                                               $A$2:$A$18,""),      
  SMALL(IF((IF(NOT(
      IF( COUNTIF(Roster!D$4:D$16,"D") >=2,  ($A$2:$A$18="D") )  +
      IF( COUNTIF(Roster!D$4:D$16,"E") >=2,  ($A$2:$A$18="E") )   +
      IF( COUNTIF(Roster!D$4:D$16,"N") >=2,  ($A$2:$A$18="N") )),
                                                                              $A$2:$A$18,"")<>""), ROW(INDIRECT("1:"&COUNTA($A$2:$A$18))),""),ROW($A1))),"")
So your initial shift codes are in $A$2:$A$18, and the first day of interest in the roster table is Roster!D$4:D$16 (so staff to be scheduled are on those same rows). I'm curious what the answer to my question above is, because if you did, the only other place to look is the data validation formula.
Yeah so after the formula was amended i deleted all existing data out and started fresh in M3 where I pasted the formula and dragged it down and repeated the process for all 28 columns. I've repeated this process to make 4 other helper tables which look at the different skill mix throughout the employed staff. I've had to change the validation formula to align with each helper table but its all running smoothly this end currently. I'll find someone with excel 2013 and test it out fully tomorrow and let you know how it goes.
Thanks again for all the time and effort you've put into his to make it succeed!!AMAZING!

Cell Formulas
RangeFormula
O2:S2O2=N2+1
M3:S19M3=IFERROR(INDEX(IF(NOT(IF(COUNTIF(Roster!D$4:D$16,"D")>=2,($A$2:$A$18="D"))+IF(COUNTIF(Roster!D$4:D$16,"E")>=2,($A$2:$A$18="E"))+IF(COUNTIF(Roster!D$4:D$16,"N")>=2,($A$2:$A$18="N"))),$A$2:$A$18,""),SMALL(IF((IF(NOT(IF(COUNTIF(Roster!D$4:D$16,"D")>=2,($A$2:$A$18="D"))+IF(COUNTIF(Roster!D$4:D$16,"E")>=2,($A$2:$A$18="E"))+IF(COUNTIF(Roster!D$4:D$16,"N")>=2,($A$2:$A$18="N"))),$A$2:$A$18,"")<>""),ROW(INDIRECT("1:"&COUNTA($A$2:$A$18))),""),ROW($A1))),"")
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
So i protected the sheet and then on unprotecting, all the data validation has been removed from all of the cells until you select them and reinstate them. This is a tedious task that i thought would just stay with the cell once it was in there. Is there any way to stop this from happen? Sorry Kirk for the million questions #rookie
 
Upvote 0
I'm sorry you encountered that issue...that's a known problem, and I'm not sure why Microsoft does that. In many cases, it makes sense to protect a sheet from edits, and there would be nothing stopping someone from pasting a non-data-validation cell into your roster scheduling table and then manually entering whatever shift code they wanted. So depending on the extent to which someone might accidentally mess up the sheet or the extent to which someone might intentionally attempt to undermine the sheet's workings, those would dictate what types of controls to apply. I think if you want both (sheet protection and data validation) you might need to use VBA code. I'm not well versed in that to advise, but others on this forum are...although if you go that route, you would be better served starting a new thread focused only on preserving Data Validation while protecting the sheet from edits...other than using the input dropdowns as intended for regular users, and editing other details (staff, notes, and dates) as the roster table changes month by month. The reason is that new threads draw more attention and there is a better chance that a descriptive thread subject line that mentions something like "how to preserve data validation in cells while protecting worksheet...VBA maybe?" would probably draw the right experts. If you explore that route, you may want to confirm with your IT department that running VBA code in a workbook is okay (some have restrictions).

As a side note...about the IT department, they may be aware, but if not, MS will be discontinuing support for Excel 2013 in April 2023. It will still work after that, but security updates and other updates will not be pushed out:

When you have an opportunity, could you also post the Data Validation "Source" formula for two different roster blocks that you've described, where each block is tailored to a particular staff skill set... perhaps the upper left cell of two blocks. I haven't identified any issues with your helper formula, so either I am missing something with that formula, or the Data Validation Source formula isn't behaving as intended.
 
Upvote 0
I'm sorry you encountered that issue...that's a known problem, and I'm not sure why Microsoft does that. In many cases, it makes sense to protect a sheet from edits, and there would be nothing stopping someone from pasting a non-data-validation cell into your roster scheduling table and then manually entering whatever shift code they wanted. So depending on the extent to which someone might accidentally mess up the sheet or the extent to which someone might intentionally attempt to undermine the sheet's workings, those would dictate what types of controls to apply. I think if you want both (sheet protection and data validation) you might need to use VBA code. I'm not well versed in that to advise, but others on this forum are...although if you go that route, you would be better served starting a new thread focused only on preserving Data Validation while protecting the sheet from edits...other than using the input dropdowns as intended for regular users, and editing other details (staff, notes, and dates) as the roster table changes month by month. The reason is that new threads draw more attention and there is a better chance that a descriptive thread subject line that mentions something like "how to preserve data validation in cells while protecting worksheet...VBA maybe?" would probably draw the right experts. If you explore that route, you may want to confirm with your IT department that running VBA code in a workbook is okay (some have restrictions).

As a side note...about the IT department, they may be aware, but if not, MS will be discontinuing support for Excel 2013 in April 2023. It will still work after that, but security updates and other updates will not be pushed out:

When you have an opportunity, could you also post the Data Validation "Source" formula for two different roster blocks that you've described, where each block is tailored to a particular staff skill set... perhaps the upper left cell of two blocks. I haven't identified any issues with your helper formula, so either I am missing something with that formula, or the Data Validation Source formula isn't behaving as intended.
Morning Kirk, thankyou for your feedback and advice. I've created a new tread asking the question on preserving the data while the sheet is protected. Worst case scenario, I'll leave the sheet unprotected as they will really only be focused on entering their shifts rather than looking at formulas and deleting things out.

I've sent an email to our IT department to let them know and asking what their plans are going forward in keeping up to date with microsoft office. As these formulas work within both excel programs, I'm not worried if they upgrade the whole system.

Below is the data validation for graduates and students.
=OFFSET(Valid!M$24,,,SUM(N(Valid!M$3:M$19<>"")),1)
Roster Template.xlsx
BCDE
72STEPHANIE AMADEI- WW/ND0.84
73SARAH BOTHERAS- ND/WW0.84
74KATE WIRGES- ND/WW0.84
Roster
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D72,F72:AE72Cell Valuecontains ""textNO
D72,F72:AE72Cell Valuecontains ""textNO
D72,F72:AE72Cell Valuecontains ""textNO
AD122:AE126,W122:X126,P122:Q126,I122:J126,I118:J120,P118:Q120,W118:X120,AD118:AE120,D114:AE117,D86:AE88,D90:AD90,D6:AE6,D14:AE14,D26:D28,D20:AE20,D22:AE22,D32:D38,D41:D71,D73:D78,H76:AE78,G77:G82,F76:F78,F73:AE75,F41:AE71,F32:AE38,F26:AE28,E33:E35,E27,E29Cell Valuecontains ""textNO
AD122:AE126,W122:X126,P122:Q126,I122:J126,I118:J120,P118:Q120,W118:X120,AD118:AE120,D114:AE117,D86:AE88,D90:AD90,D6:AE6,D14:AE14,D26:D28,D20:AE20,D22:AE22,D32:D38,D41:D71,D73:D78,H76:AE78,G77:G82,F76:F78,F73:AE75,F41:AE71,F32:AE38,F26:AE28,E33:E35,E27,E29Cell Valuecontains ""textNO
AD122:AE126,W122:X126,P122:Q126,I122:J126,I118:J120,P118:Q120,W118:X120,AD118:AE120,D114:AE117,D86:AE88,D90:AD90,D6:AE6,D14:AE14,D26:D28,D20:AE20,D22:AE22,D32:D38,D41:D71,D73:D78,H76:AE78,G77:G82,F76:F78,F73:AE75,F41:AE71,F32:AE38,F26:AE28,E33:E35,E27,E29Cell Valuecontains ""textNO
Cells with Data Validation
CellAllowCriteria
D72:E74List=OFFSET(Valid!M$24,,,SUM(N(Valid!M$3:M$19<>"")),1)


Roster Template.xlsx
LMN
22graduate helper columns
2312
24DD
25EE
26NN
Valid
Cell Formulas
RangeFormula
M24:N26M24=IFERROR(INDEX(IF(NOT(IF(COUNTIF(Roster!D$72:D$79,"D")>=2,($A$2:$A$18="D"))+IF(COUNTIF(Roster!D$72:D$79,"E")>=2,($A$2:$A$18="E"))+IF(COUNTIF(Roster!D$72:D$79,"N")>=2,($A$2:$A$18="N"))),$A$2:$A$18,""),SMALL(IF((IF(NOT(IF(COUNTIF(Roster!D$72:D$79,"D")>=2,($A$2:$A$18="D"))+IF(COUNTIF(Roster!D$72:D$79,"E")>=2,($A$2:$A$18="E"))+IF(COUNTIF(Roster!D$72:D$79,"N")>=2,($A$2:$A$18="N"))),$A$2:$A$18,"")<>""),ROW(INDIRECT("1:"&COUNTA($A$2:$A$18))),""),ROW($A1))),"")


Students
=OFFSET(Valid!M$45,,,SUM(N(Valid!M$3:M$19<>"")),1)
Roster Template.xlsx
BCDE
80JODIE HOLMES0.63
81MEREDITH JOHNSON0.63
82CAROLYN KNIGHT0.63
Roster
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D80:F83,H80:AE83Cell Valuecontains ""textNO
D80:F83,H80:AE83Cell Valuecontains ""textNO
D80:F83,H80:AE83Cell Valuecontains ""textNO
Cells with Data Validation
CellAllowCriteria
D80:E82List=OFFSET(Valid!M$45,,,SUM(N(Valid!M$3:M$19<>"")),1)


Roster Template.xlsx
LMN
43Student helper column
4412
45DD
46EE
47NN
Valid
Cell Formulas
RangeFormula
M45:N47M45=IFERROR(INDEX(IF(NOT(IF(COUNTIF(Roster!D$80:D$83,"D")>=1,($A$2:$A$18="D"))+IF(COUNTIF(Roster!D$80:D$83,"E")>=1,($A$2:$A$18="E"))+IF(COUNTIF(Roster!D$80:D$83,"N")>=1,($A$2:$A$18="N"))),$A$2:$A$18,""),SMALL(IF((IF(NOT(IF(COUNTIF(Roster!D$80:D$83,"D")>=1,($A$2:$A$18="D"))+IF(COUNTIF(Roster!D$80:D$83,"E")>=1,($A$2:$A$18="E"))+IF(COUNTIF(Roster!D$80:D$83,"N")>=1,($A$2:$A$18="N"))),$A$2:$A$18,"")<>""),ROW(INDIRECT("1:"&COUNTA($A$2:$A$18))),""),ROW($A1))),"")
 
Upvote 0
Hi Andrea, I took a peek at your other thread (hope you find some good advice about how to implement a VBA script)...I think that may be the only way to do both--use formulas for creating data validation lists and Data Validation on the inputs while also preventing overwriting of roster sheet cells.

But something struck me when I saw your OFFSET formulas for two of the table blocks. Here is what mine looks like:
Excel Formula:
=OFFSET(W$3,,,SUM(N(W$3:W$11<>"")),1)
The OFFSET function is used to select some range of interest on a worksheet and it takes 5 arguments. The 1st is the anchor point for the range to be selected...that is, some knowable cell that makes sense. The 2nd and 3rd arguments describe how many rows and columns to step away from this anchor point before we begin aggregating cells into a range. In our case, we want to specify the top cell of the day of interest in the helper table. In my case, that cell is W$3 and in your last post, I am guessing that you have a helper table whose top dropdown data item resides in Valid!M$45. Then we are not interested in stepping away from this anchor point...we want our range of cells to be collected beginning right at the anchor point, so the 2nd and 3rd arguments are to be ignored...that is why the formula has a set of triple commas, where you can see that a row offset number would fit between the first pair in that triplet and the the column offset number between the second pair in that triplet of commas. Then we move to the 4th and 5th arguments, which represent the height and width of the range to be selected. The height is the number of nonblank cells in the helper table column for that same day. So in my example above, I used the construction SUM(N(W$3:W$11<>"")). The W$3:W$11 part represents the entire column range of my helper table for some specific day. But all of those cells may not be populated with shift codes because some have been removed by the other formula. To determine how many cells are not blank I perform a logic test W$3:W$11<>"" which will produce an array of TRUE's and FALSE's in the same order as W3<>"", W4<>"", W5<>"", etc. (W3 is not blank, True or False?, and so on for each logical test). This array of TRUE's and FALSE's is converted into 1's and 0's using the N function, so the entire TRUE/FALSE array building part of formula is wrapped inside an N function. And finally that array of 1's and 0's is summed. That sum represents the height of the range that the OFFSET function should select. And then we want OFFSET to return only this single column so the width of the range to return is 1. The key takeaway is that the 1st argument in the OFFSET function (my W$3 and your Valid!M$45) needs to be the same starting point for constructing the nonblank-counting SUM formula in the 4th argument. That's why my logical test is W$3:W$11<>"" (note the W$3 stating location, extending down to W$11). But your 4th argument is counting some other range that is not related to Valid!M$45...you have Valid!M$3:M$19<>"".

Let me know if this is clear enough to help you do some debugging. I suspect this is why you're getting some odd results at times. If you do have a dropdown column beginning in Valid!M$45, what is the lower cell reference of that same dropdown column? That's what you will want for the 4th argument. Pay careful attention that what gets "fixed". You want only the row numbers fixed, not the columns, so the $ signs appear before the row numbers when the ranges are specified.
 
Upvote 0
Hi Andrea, I took a peek at your other thread (hope you find some good advice about how to implement a VBA script)...I think that may be the only way to do both--use formulas for creating data validation lists and Data Validation on the inputs while also preventing overwriting of roster sheet cells.

But something struck me when I saw your OFFSET formulas for two of the table blocks. Here is what mine looks like:
Excel Formula:
=OFFSET(W$3,,,SUM(N(W$3:W$11<>"")),1)
The OFFSET function is used to select some range of interest on a worksheet and it takes 5 arguments. The 1st is the anchor point for the range to be selected...that is, some knowable cell that makes sense. The 2nd and 3rd arguments describe how many rows and columns to step away from this anchor point before we begin aggregating cells into a range. In our case, we want to specify the top cell of the day of interest in the helper table. In my case, that cell is W$3 and in your last post, I am guessing that you have a helper table whose top dropdown data item resides in Valid!M$45. Then we are not interested in stepping away from this anchor point...we want our range of cells to be collected beginning right at the anchor point, so the 2nd and 3rd arguments are to be ignored...that is why the formula has a set of triple commas, where you can see that a row offset number would fit between the first pair in that triplet and the the column offset number between the second pair in that triplet of commas. Then we move to the 4th and 5th arguments, which represent the height and width of the range to be selected. The height is the number of nonblank cells in the helper table column for that same day. So in my example above, I used the construction SUM(N(W$3:W$11<>"")). The W$3:W$11 part represents the entire column range of my helper table for some specific day. But all of those cells may not be populated with shift codes because some have been removed by the other formula. To determine how many cells are not blank I perform a logic test W$3:W$11<>"" which will produce an array of TRUE's and FALSE's in the same order as W3<>"", W4<>"", W5<>"", etc. (W3 is not blank, True or False?, and so on for each logical test). This array of TRUE's and FALSE's is converted into 1's and 0's using the N function, so the entire TRUE/FALSE array building part of formula is wrapped inside an N function. And finally that array of 1's and 0's is summed. That sum represents the height of the range that the OFFSET function should select. And then we want OFFSET to return only this single column so the width of the range to return is 1. The key takeaway is that the 1st argument in the OFFSET function (my W$3 and your Valid!M$45) needs to be the same starting point for constructing the nonblank-counting SUM formula in the 4th argument. That's why my logical test is W$3:W$11<>"" (note the W$3 stating location, extending down to W$11). But your 4th argument is counting some other range that is not related to Valid!M$45...you have Valid!M$3:M$19<>"".

Let me know if this is clear enough to help you do some debugging. I suspect this is why you're getting some odd results at times. If you do have a dropdown column beginning in Valid!M$45, what is the lower cell reference of that same dropdown column? That's what you will want for the 4th argument. Pay careful attention that what gets "fixed". You want only the row numbers fixed, not the columns, so the $ signs appear before the row numbers when the ranges are specified.
Great explanation of these 5 arguments and I've been testing them in different variations today. My biggest problem now is even when i haven't got the sheet protected and exit it and come back in, I'm only getting one drop down box option even though the correct data validation is applied to all the cells
1653735761294.png


Roster debugged familarisation.xlsx
EFG
1TWT
2567
3
4
5
Roster
Cell Formulas
RangeFormula
E2:G2E2=D2+1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D3:W3Cell Valuecontains ""textNO
D3:W3Cell Valuecontains ""textNO
D3:W3Cell Valuecontains ""textNO
D12:AE12,D16:AE16,D4:AE10Cell Valuecontains ""textNO
D12:AE12,D16:AE16,D4:AE10Cell Valuecontains ""textNO
D12:AE12,D16:AE16,D4:AE10Cell Valuecontains ""textNO
Cells with Data Validation
CellAllowCriteria
E3:AE3List=Valid!$A$2:$A$17
E4:AE16List=OFFSET(Valid!N$3,,,SUM(N(Valid!N$3:N$19<>"")),1)
 
Upvote 0
when i haven't got the sheet protected and exit it and come back in, I'm only getting one drop down box option even though the correct data validation is applied to all the cells
When this happens, if you go to the dropdown list table for that day, do you still see the entire list of valid shift codes...or do you see only one item in that list? I'm trying to understand where the issue is.
 
Upvote 0
When this happens, if you go to the dropdown list table for that day, do you still see the entire list of valid shift codes...or do you see only one item in that list? I'm trying to understand where the issue is.
Im only seeing the one 'D' item. If i enter two "D' for the day it then will allow me to have an 'E' but i need the whole list to choose from. All the shifts are still listed when having a look at the vaild sheet and helper columns
 
Upvote 0
Could you check one other thing, please? At the end of the formula that creates the dropdown lists, there should be a ROW($A1). That part of the formula does nothing more than initially return a 1, and then as the formula is dragged down to build the dropdown list item by item, the ROW($A1) will change to ROW($A2), ROW($A3), etc...which returns 2 and then 3, and so on. That trick is used to tell the SMALL function appearing earlier in the formula which particular item to return from the available shift codes...and because of that, anytime the formula containing the ROW($A1) is pasted into another dropdown block (perhaps one lower on the page), you should check that it still says ROW($A1) for the uppermost cell in that dropdown block. As the formula is written, the cell reference will automatically update to a different cell address that you do not want...you want the ROW argument to always start with $A1 no matter where it is copied (actually any column reference followed by 1...the "1" is the critical part that ensures this component of the formula will return a 1 initially). If you do not do this--and let's say you've pasted this dropdown list-generating formula on a lower row such that you see ROW($A20)--then the SMALL function will attempt to return the 20th, then the 21st, and so on elements from the list of available shift codes...which may result in either a shortened list appearing or nothing at all.

If you would like, I would be happy to have a closer look at your file if you want to upload a de-sensitized version (names/organizations can be deleted or overwritten with generic content) of it to a file sharing site (e.g., Dropbox, Google, Box, etc.)...and then share the link.
 
Upvote 0
Could you check one other thing, please? At the end of the formula that creates the dropdown lists, there should be a ROW($A1). That part of the formula does nothing more than initially return a 1, and then as the formula is dragged down to build the dropdown list item by item, the ROW($A1) will change to ROW($A2), ROW($A3), etc...which returns 2 and then 3, and so on. That trick is used to tell the SMALL function appearing earlier in the formula which particular item to return from the available shift codes...and because of that, anytime the formula containing the ROW($A1) is pasted into another dropdown block (perhaps one lower on the page), you should check that it still says ROW($A1) for the uppermost cell in that dropdown block. As the formula is written, the cell reference will automatically update to a different cell address that you do not want...you want the ROW argument to always start with $A1 no matter where it is copied (actually any column reference followed by 1...the "1" is the critical part that ensures this component of the formula will return a 1 initially). If you do not do this--and let's say you've pasted this dropdown list-generating formula on a lower row such that you see ROW($A20)--then the SMALL function will attempt to return the 20th, then the 21st, and so on elements from the list of available shift codes...which may result in either a shortened list appearing or nothing at all.

If you would like, I would be happy to have a closer look at your file if you want to upload a de-sensitized version (names/organizations can be deleted or overwritten with generic content) of it to a file sharing site (e.g., Dropbox, Google, Box, etc.)...and then share the link.
If you'd be happy to have a look at it that would be phenomenal! whats your email address that i should send it to?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top