+ Reply to Thread
Results 1 to 13 of 13

How do i prevent special characters from being input into a cell?

Hybrid View

  1. #1
    Registered User
    Join Date
    12-22-2011
    Location
    americuh
    MS-Off Ver
    Excel 2003
    Posts
    36

    How do i prevent special characters from being input into a cell?

    I have a spreadsheet where in one column the users must input alphanumerics, but no special characters, and another column where they should only input numbers. Both of these cases are issues where they have a tendency to input things that shouldnt be there which causes alot of problems with the rest of the spreadsheet, how do i prevent those things from being input into the cells (without using macros)?

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How do i prevent special characters from being input into a cell?

    Hi,

    Re the first part, do you have an exhaustive list of all the special characters that they are not allowed to enter?

    Re the second, are there any refinements to that criteria, or are you happy if it's simply 'a' number?

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: How do i prevent special characters from being input into a cell?

    You can do this using data validation.

    However, this can be defeated by copying and pasting into the target cells or by dragging and dropping into the target cells.

    You need to better define "alphanumerics". Does that mean a combination of the letters A to Z and the numbers 0 to 9? Does the case of the letters matter? How about the length of the string?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Registered User
    Join Date
    12-22-2011
    Location
    americuh
    MS-Off Ver
    Excel 2003
    Posts
    36

    Re: How do i prevent special characters from being input into a cell?

    Well for the first case, i mean just letters and numbers, no )(*#@$&(&^@!#& stuff. Case doesnt matter, length doesnt matter though it probably wont be more than 100 characters.

    For the second case i just want it to be a number, nothing else.

  5. #5
    Registered User
    Join Date
    12-22-2011
    Location
    americuh
    MS-Off Ver
    Excel 2003
    Posts
    36

    Re: How do i prevent special characters from being input into a cell?

    if i had to pick which special characters i dont want, it would be...... / _ - , \ ( ) | { } [ ]

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: How do i prevent special characters from being input into a cell?

    Quote Originally Posted by poof View Post
    Well for the first case, i mean just letters and numbers, no )(*#@$&(&^@!#& stuff. Case doesnt matter
    Try this...

    First, create this named expression...

    Goto the menu Insert>Name>Define
    Name: String
    Refers to: ="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    OK out

    Apply the validation...

    Let's assume you want this to apply to cell A1.

    Select cell A1
    Goto the menu Data>Validation
    Allow: Custom
    Formula:

    =AND(SEARCH(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),String))

    Uncheck: Ignore blank
    OK out

    If you get this warning: "The formula currently evaluates to an error. Do you wish to continue?" Just answer Yes.

    If you want to test that formula as a formula in a worksheet cell it must be array entered.

    Array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    For the second case i just want it to be a number, nothing else.
    Do you want to allow ANY number like 2.5 or do you just want whole numbers like 2?

    If you want ANY number then:

    Data>Validation
    Allow: Custom
    Formula: =ISNUMBER(A1)

    If you just want whole numbers then:

    Data>Validation
    Allow: Custom
    Formula: =INT(A1)=A1

  7. #7
    Registered User
    Join Date
    12-22-2011
    Location
    americuh
    MS-Off Ver
    Excel 2003
    Posts
    36

    Re: How do i prevent special characters from being input into a cell?

    Quote Originally Posted by Tony Valko View Post
    Try this...

    First, create this named expression...

    Goto the menu Insert>Name>Define
    Name: String
    Refers to: ="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    OK out

    Apply the validation...

    Let's assume you want this to apply to cell A1.

    Select cell A1
    Goto the menu Data>Validation
    Allow: Custom
    Formula:

    =AND(SEARCH(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),String))

    Uncheck: Ignore blank
    OK out

    If you get this warning: "The formula currently evaluates to an error. Do you wish to continue?" Just answer Yes.

    If you want to test that formula as a formula in a worksheet cell it must be array entered.

    Array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.


    Do you want to allow ANY number like 2.5 or do you just want whole numbers like 2?

    If you want ANY number then:

    Data>Validation
    Allow: Custom
    Formula: =ISNUMBER(A1)

    If you just want whole numbers then:

    Data>Validation
    Allow: Custom
    Formula: =INT(A1)=A1

    I entered it as a data validation in the cell as you described, but applied it to E2 instead of A1 like so:

    =AND(SEARCH(MID(E2,ROW(INDIRECT("1:"&LEN(E2))),1),String))

    and okayd through it, then put some special characters in the cell and they entered fine, so that didnt work.

    Then i tried the ctrl shift enter method of putting the formula in the cell but it gave me a circular reference error.

    The datavalidation number-only method works fine for my other problem though!

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: How do i prevent special characters from being input into a cell?

    Tell me what cell(s) you want this to apply to and I'll post a sample file.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: How do i prevent special characters from being input into a cell?

    If you just want whole numbers then:

    Data>Validation
    Allow: Custom
    Formula: =INT(A1)=A1
    Or Data > Data Validation > Allow: Whole number
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1