Data Validation formula

dommmm

New Member
Joined
Feb 6, 2020
Messages
10
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
Hi,
I'm trying to concatenate 2 custom formulas to use in data validation.

I need to restrict:
1) text length (numbers or alpha) greater than 20 characters
2) The use of ' (apostrophe) and * (Asterix)

I have:
=IF(OR(LEN(A1)>18),FIND("*",A1))

but this wont allow any data to be typed in at all. I can make them work as individual queries but I need to have multiple validation on the same cell.

Please help.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
If both conditions have to be true then try

=AND(LEN(A1)>18,FIND("*",A1))
 
Upvote 0
1581000686499.png
 
Upvote 0
Does this work?

=NOT(OR(LEN(A1)>20,LEN(A1)<>LEN(SUBSTITUTE(A1,"*","")),LEN(A1)<>LEN(SUBSTITUTE(A1,"'",""))))
 
Upvote 0
Think the error is because your cell is probably empty, the validation should still work though if you say Yes to continue
 
Upvote 0
Does this work?

=NOT(OR(LEN(A1)>20,LEN(A1)<>LEN(SUBSTITUTE(A1,"*","")),LEN(A1)<>LEN(SUBSTITUTE(A1,"'",""))))

WOW that is brilliant and it works. I need to spend 5 mins reading through the formula though to understand it ;)
 
Upvote 0
WOW that is brilliant and it works. I need to spend 5 mins reading through the formula though to understand it ;)

You're welcome!

The challenge is that an asterisk is a special character for a wildcard. Preventing an asterisk in Data Validation basically says "Don't allow anything".

SUBSTITUTE is good because if it doesn't find an asterisk it doesn't throw an error like FIND would. If there's any asterisk or apostrophe the SUBSITUTE replaces it with a null so the length will be shorter than the original text.
 
Upvote 0
You're welcome!

The challenge is that an asterisk is a special character for a wildcard. Preventing an asterisk in Data Validation basically says "Don't allow anything".

SUBSTITUTE is good because if it doesn't find an asterisk it doesn't throw an error like FIND would. If there's any asterisk or apostrophe the SUBSITUTE replaces it with a null so the length will be shorter than the original text.

Ah right, sorry if it's meant to discount the ' or * by changing them to "" then it doesn't work correctly.

If I enter "abcdefghijklmnopqrst" in A1 (20 characters) then it's fine but if I change the "o" for a "*" it gives error - it does what I need but I read that you thought it should take the * out, which would then allow me to add a "u" on the end ??
 
Upvote 0
It's a data validation so SUBSTITUTE only removes the * or ' as a part of the validation, it won't make changes to what's entered.

I understood you wanted to restrict entry to maximum 20 characters containg no "*" or "'". Did I misunderstand?
 
Upvote 0

Forum statistics

Threads
1,214,883
Messages
6,122,077
Members
449,064
Latest member
MattDRT

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