Data validation - two conditions based on length of text

Kra

Board Regular
Joined
Jul 4, 2022
Messages
160
Office Version
  1. 365
Platform
  1. Windows
Hello!

I am trying to apply a data validation to a range of cells to restrict the length of the input based on two conditions.

If cell in column B contains text "BAR", then input in cell A cannot be longer than 34 characters.
If cell in column B contains anything else (can be empty as well), then input in cell A cannot be longer than 40 characters.

I used this formula as custom data validation:

=OR(AND(B3="BAR";LEN(A3)>34);LEN(A3)>40)

But it triggers data validation even if input in cell A is only 1 character long now. How can it be corrected?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
try
=IF(AND(B3="BAR",LEN(A3)<=34),TRUE,IF(AND(B3<>"BAR",LEN(A3)<=40),TRUE,FALSE))
 
Upvote 0
Solution

Forum statistics

Threads
1,215,523
Messages
6,125,323
Members
449,218
Latest member
Excel Master

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