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?
 
I think I have found it, I used the formula

Excel Formula:
=AND(ISERROR(SEARCH(MID(B5,ROW(INDIRECT("1:"&LEN(B5))),1),"`~!@#$%^&*()_+-=[]\{}|;’:”<>/?")))
Although you have added some more special characters, that is the exact same formula as you had in your first post, meaning it should produce the same error. if it is not causing the error then that strongly suggests that the formula in post 1 was not the exact formula that was causing the error which in turn explains why it was not possible to find the cause.
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.
When I use that formula as a validation rule for B5 it prevents any of the listed characters from being entered with or without text.
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I am not sure what I did as using the formula now gives me an error with anything entered.
Excel Formula:
       =AND(ISERROR(SEARCH(MID(B5,ROW(INDIRECT("1:"&LEN(B5))),1),"`~!@#$%^&*()_+-=[]\{}|;’:”<>/?")))

Would it be best to try a vba solution as I cannot find any function that solves my problem?
 
Upvote 0
When I tried that formula it worked as required. If it is not working for you then chances are a vba alternative will encounter the same problem.

Try setting up the same validation rule in a new workbook and see if it works there.
 
Upvote 0
It even did it on a new workbook. My boss has told me that I can use the input text on that cell instead so thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,214,917
Messages
6,122,233
Members
449,075
Latest member
staticfluids

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