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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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,224,560
Messages
6,179,520
Members
452,921
Latest member
BBQKING

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