Formula to go in the data validation that prevents special characters from being entered in a cell

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I need to prevent certain special characters from being entered into B5. I want to do this with data validation.

This is the formula I used but it gave me an error saying A named range you specified cannot be found.
Excel Formula:
=AND(ISERROR(SEARCH(MID(B5,ROW(INDIRECT("1:"&LEN(B5))),1),"\/:%'*?<>|"".")))

If I removed the = sign, I didn't get that error, but it won't let me enter anything in the cell.

Can someone help me please?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Works fine for me, perhaps the error is being caused elsewhere?
 
Upvote 0
In the data validation settings box, on the input message tab, I have a message that is displayed and I have an error message that is displayed on stop.
 
Upvote 0
The error is nothing to do with the validation. If it is happening when you enter data into the cell then my best guess would be that you have another INDIRECT formula somewhere that is using the entry in the cell to form a range.

Try selecting the validation cell, then clicking 'Trace dependents' on the Formulas tab.
 
Upvote 0
I am trying a different formula and it seems to block most special characters. The only ones I will not stop from being entered are ~ * ?

I need them blocked from entry
Also, full stops and commas are blocked but I need to allow them.

This is the formula
=ISNUMBER(SUMPRODUCT(SEARCH(MID(B5,ROW(INDIRECT("6:"&LEN(B5))),1)
," "&"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")))

Thanks
 
Upvote 0
I think I have found it, I used the formula

Excel Formula:
=AND(ISERROR(SEARCH(MID(B5,ROW(INDIRECT("1:"&LEN(B5))),1),"`~!@#$%^&*()_+-=[]\{}|;’:”<>/?")))
 
Upvote 0
Actually, with the above formula, if I enter the special characters on their own, I get the error but if I enter them with some text, I do not get an error. Therefore, it allows them and it shouldn't, so the above formula doesn't work.
 
Upvote 0
I found a formula that appears to be working at the moment.

ISNUMBER(SUMPRODUCT(FIND(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),",.’abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ")))
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,891
Members
449,194
Latest member
JayEggleton

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