Formula in a Custom Data Validation is not working when a criteria cell is Blank

narendra

Board Regular
Joined
Apr 15, 2008
Messages
95
A user enters:
1) The Start date of the month in Cell B1
2) The joining date (in case of a new employee) in Cell B2
3) Number of days worked in the current month in Cell B3 which has a custom data validation check as follows:
=AND(OR(MOD(B3,1)=0.5,MOD(B3,1)=0),B3>=0,B3<=(DAY(EOMONTH(B1,0))-IF(B2=0,DAY(B1),DAY(B2))+1))
which is to make sure that the no. of days worked do not exceed the total no. of days available in that month, from the start of the month or, from the joining date -in case of a new employee.

This Data validation check works if there is a joining date, but it fails to restrict an incorrect value if the joining date (cell B2) is blank.
The same custom validation Formula in Cell B4 works correctly even when the joining date is blank. But somehow fails to work in a data validation.
How can I fix the data validation to work correctly?


Book1
ABC
1Enter the Beginning Date of this month:1-Jul-23← this month has 31 days
2Enter the Joining Date (for new employees) :← so when this is Blank (no joining date)
3Days Worked in this month (including half working days) :32← Custom Data Validation accepted this value
4Data Validation criteria in Cell B3 :FALSE← however the Formula used in above Custom Data Validation triggers False
Sheet1
Cell Formulas
RangeFormula
B4B4=AND(OR(MOD(B3,1)=0.5,MOD(B3,1)=0),B3>=0,B3<=(DAY(EOMONTH(B1,0))-IF(B2=0,DAY(B1),DAY(B2))+1))
Cells with Data Validation
CellAllowCriteria
B2Datebetween B1 and EOMONTH(B1,0)
B3Custom=AND(OR(MOD(B3,1)=0.5,MOD(B3,1)=0),B3>=0,B3<=(DAY(EOMONTH(B1,0))-IF(B2=0,DAY(B1),DAY(B2))+1))
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I made a quick change to the formula and now it works even when cell B2 is blank.

At first, I simplified the formula by removing the DAY function from the Date math, which gave me =AND(OR(MOD(B3,1)=0.5,MOD(B3,1)=0),B3>=0,B3<=(EOMONTH(B1,0)-IF(B2=0,B1,B2)+1)). However that did not work.
Thereafter, I changed the custom data validation formula by replacing the last IF criteria with a MAX function (appropriate for this case), which works even when cell B2 is blank!
The updated formula is: =AND(OR(MOD(B3,1)=0.5,MOD(B3,1)=0),B3>=0,B3<=(EOMONTH(B1,0)-MAX(B1,B2)+1))

Note:
Since I thought that the problem is with the IF function, I tried to wrap the dates in the end with a DAY function like this
=AND(OR(MOD(B3,1)=0.5,MOD(B3,1)=0),B3>=0,B3<=(DAY(EOMONTH(B1,0))-MAX(DAY(B1),DAY(B2))+1)), but again, it stopped working when cell B2 is blank?

So it seems that both IF and DAY function have problems inside custom data validation when they are referring to Blank cell(s).
Does anyone know what's really happening in excel?

FYI, this was tested in Excel 2010 32-bit which is on Win 64-bit. Not sure if that has anything to do with the problem.


Book1
ABC
1Enter the Beginning Date of this month:1-Jul-23← this month has 31 days
2Enter the Joining Date (for new employees) :← this is Blank (no joining date)
3Days Worked in this month (including half working days) :31← Max value accepted by Custom Data Validation for this month
4Data Validation criteria in Cell B3 :TRUE← the Formula used in above Custom Data Validation
Sheet1
Cell Formulas
RangeFormula
B4B4=AND(OR(MOD(B3,1)=0.5,MOD(B3,1)=0),B3>=0,B3<=(EOMONTH(B1,0)-MAX(B1,B2)+1))
Cells with Data Validation
CellAllowCriteria
B2Datebetween B1 and EOMONTH(B1,0)
B3Custom=AND(OR(MOD(B3,1)=0.5,MOD(B3,1)=0),B3>=0,B3<=(EOMONTH(B1,0)-MAX(B1,B2)+1))
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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