Data Validation with conditions

Fahad987

New Member
Joined
Nov 29, 2021
Messages
6
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
Hi,

I am working on setting up custom data validation as data is entered by the user. I have two columns A and B. In column A, i enter today's date (not using today() function). It is a named range with name "myDate". In column B, i type in customer names. however, sometimes there are a lot of customer names to enter and one or two names get typed again. I want to apply data validation on column B such that for only today's entries, if i happen to enter any customers' name twice in column B, the data validation rule prompts me that it has already been entered. For now, i am trying to enter this into my custom data validation rule:
=IF(myDate=today(), Countif($B$2:$B$50,B2)=1, 0)
But it does not restrict any duplicate entries in column B. When I use this countif formula without the IF condition only on column B data range, it works fine.

My Current data structure:

ColumnA ColumnB
myDate CustomerNames
29-11-2021 ABC
29-11-2021 LMN
30-11-2021 ABC
30-11-2021 LMN
30-11-2021 XYZ
30-11-2021 ABC <--- Here it should give me error message but only based on today's datewise entries.

I need this date conditional check because for the next day, i will resume data entries from right beneath my today's entries. So help from forum members here would be really great.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,238
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
Excel Formula:
=COUNTIFS($A$2:$A$50,A2,$B$2:$B$50,B2)=1
 

Fahad987

New Member
Joined
Nov 29, 2021
Messages
6
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
Excel Formula:
=COUNTIFS($A$2:$A$50,A2,$B$2:$B$50,B2)=1
Dear Fluff,

Thank you. it seems to be working. However, can you please explain the logic behind its working. Why would i include the column A i.e. current date into the countif statement. Firstly, because the date is repeating itself downwards for today's entries, and secondly, i am supposed to be checking for data validation in column B, not column A. i'd be grateful.
 

Fahad987

New Member
Joined
Nov 29, 2021
Messages
6
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
One more thing though. I am using Excel 2003. I tried your solution in Excel 2010 and it works. However, can you specifically help me out with respect to Excel 2003 version?
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
54,365
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Try this for your column B Data Validation formula, starting at cell B2
Excel Formula:
=SUMPRODUCT(--(A$2:A$50&B$2:B$50=A2&B2))=1

You need column A in the checking process because it is okay (as I understand it) to enter the same name in column B on different days. It is only when you enter the same column B with the same column A date that is the problem.
Looking at your original example in post #1: If we only looked at column B then the 3rd entry in column B would have been disallowed since ABC had already been entered.
However, by including a check of the date column that third entry is allowed but the last entry is disallowed because the combination of data and customer has already been used.
 
Solution

Fahad987

New Member
Joined
Nov 29, 2021
Messages
6
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
Try this for your column B Data Validation formula, starting at cell B2
Excel Formula:
=SUMPRODUCT(--(A$2:A$50&B$2:B$50=A2&B2))=1

You need column A in the checking process because it is okay (as I understand it) to enter the same name in column B on different days. It is only when you enter the same column B with the same column A date that is the problem.
Looking at your original example in post #1: If we only looked at column B then the 3rd entry in column B would have been disallowed since ABC had already been entered.
However, by including a check of the date column that third entry is allowed but the last entry is disallowed because the combination of data and customer has already been used.
Unfortunately, this is not giving the desired result. Before applying data validation rule, i select the whole desired range in column B, then after entering the above formula, when i enter data in very first cell in column B, it gives me error message right away.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
54,365
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Before applying data validation rule, i select the whole desired range in column B
What is that range?
 

Fahad987

New Member
Joined
Nov 29, 2021
Messages
6
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
Range is from cell B2 to B50. but it gives me error in cell B2 as soon as i enter something in it. and it happens downwards as well in any other cell within the range where i try to type something.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
54,365
Office Version
  1. 365
Platform
  1. Windows
Sorry, I cannot reproduce what you are describing. The Data Validation works fine for me.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,238
Office Version
  1. 365
Platform
  1. Windows
Peter's formula works for me as well, did you use exactly what Peter suggested, or did you change it to include your named range?
Not sure this will work any better but try
Excel Formula:
=SUMPRODUCT((A$2:A$50=A2)*(B$2:B$50=B2))=1
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,124
Messages
5,835,544
Members
430,366
Latest member
glastonbury

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
Top