KutoolsforOffice — One Suite. Five Tools. Get More Done.

How to prevent special characters from being entered in Excel?

AuthorXiaoyangLast modified

In some worksheets, you may want cells to accept only letters and numbers while preventing special characters such as @, #, $, %, and &. This article introduces three ways to restrict special characters when values are entered in Excel.

Comparison of methods for preventing special characters

MethodHow it worksConsiderations
Data ValidationUses a custom formula to allow only letters and numbers.Built into Excel, but pasted data can bypass Data Validation.
VBA codeAutomatically clears invalid entries from a specified range.Requires a macro-enabled workbook and enabled macros.
Kutools for ExcelBlocks special characters in the selected range through the Prevent Typing dialog.No formula or VBA setup is required.

Prevent special characters with Data Validation

Excel's Data Validation feature can restrict the selected cells to letters and numbers.

  1. Select the range in which you want to prevent special characters.
  2. Click Data > Data Validation > Data Validation.
    Data Validation option on the Excel ribbon
  3. In the Data Validation dialog box, open the Settings tab and select Custom from the Allow list. Enter the following formula in the Formula box:
    =IF(A1="",TRUE,SUMPRODUCT(--ISNUMBER(FIND(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")))=LEN(A1))

    📝 Note:

    A1 must refer to the first cell in the selected range. Change it to match your actual selection. This formula allows only English letters and numbers; spaces, punctuation, and other special characters are rejected.

    Data Validation formula for restricting special characters in Excel
  4. Click OK. If you type a value containing a special character in the validated range, Excel displays a warning and rejects the entry.
    Warning displayed when a special character is entered

Prevent special characters with VBA code

The following worksheet event code checks entries in a specified range and clears any value that contains a character other than a letter or number.

  1. Press Alt + F11 to open the Microsoft Visual Basic for Applications window.
  2. In the Project Explorer, double-click the worksheet on which you want to restrict entries. Paste the following code into that worksheet's code window:
    Private Const FCheckRgAddress As String = "A1:A100"
    Private Sub Worksheet_Change(ByVal Target As Range)
    'Update 20140905
        Dim xChanged As Range
        Dim xRg As Range
        Dim xString As String
        Dim sErrors As String
        Dim xRegExp As Variant
        Dim xHasErr As Boolean
        Set xChanged = Application.Intersect(Range(FCheckRgAddress), Target)
        If xChanged Is Nothing Then Exit Sub
        Set xRegExp = CreateObject("VBScript.RegExp")
        xRegExp.Global = True
        xRegExp.IgnoreCase = True
        xRegExp.Pattern = "[^0-9a-z]"
        For Each xRg In xChanged
            If xRegExp.Test(xRg.Value) Then
                xHasErr = True
                Application.EnableEvents = False
                xRg.ClearContents
                Application.EnableEvents = True
            End If
        Next
        If xHasErr Then MsgBox "These cells had invalid entries and have been cleared:"
    End Sub
    
    VBA code for restricting special characters in Excel

    📝 Notes:

    Change A1:A100 in Private Const FCheckRgAddress As String = "A1:A100" to the range you want to monitor. Because this is worksheet event code, it must be placed in the relevant worksheet's code window, not in a standard Module. Save the workbook as a macro-enabled file.

  3. Save and close the Visual Basic editor. When a value containing a special character is entered in the specified range, the entry is cleared and a warning message appears.
    Warning dialog displayed after entering a special character

Prevent special characters with Kutools for Excel

With the Prevent Typing feature in Kutools for Excel, you can block special characters in a selected range without creating a formula or writing VBA code.

Kutools for Excel offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Integrated with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...
  1. Select the range in which you want to prevent special characters, and click Kutools > Prevent Typing > Prevent Typing.
    Kutools Prevent Typing option in Excel
  2. In the Prevent Typing dialog box, select Prevent type in special characters.
    Prevent type in special characters option in Kutools
  3. Click OK. A message warns that applying this feature will remove existing Data Validation rules from the selected range. Click Yes to continue, and then acknowledge the confirmation message.
    Confirmation messages for Kutools Prevent Typing
  4. Click OK to close the dialog box. A warning now appears whenever you try to enter a special character in the selected range.
    Warning displayed when entering a special character

💡 Tip:

If you also need to stop duplicate values from being entered in a column, try Kutools for Excel's Prevent Duplicate feature. Download and start a free trial

Kutools Prevent Duplicate option in Excel

Kutools for Excel - Supercharge Excel with over 300 essential tools, making your work faster and easier, and take advantage of AI features for smarter data processing and productivity. Get It Now


Video: Prevent special characters with Kutools for Excel

Kutools for Excel: Over 300 handy tools at your fingertips! Enjoy AI-powered features for smarter and faster work! Download Now!

Frequently asked questions

Does the Data Validation formula also block spaces?

Yes. The allowed-character string contains only English letters and numbers, so spaces are treated as invalid. To allow spaces, add a space inside the allowed-character string after 0123456789 or another convenient position.

Why can special characters still appear after I paste data?

Excel Data Validation mainly controls values typed directly into cells and can be bypassed by some paste operations. Use the VBA or Kutools method if pasted entries also need to be checked or blocked.

Can I allow selected symbols such as hyphens or periods?

Yes. With the Data Validation method, add the permitted symbols to the allowed-character string. With Kutools, use the option for allowing only specified characters and include the letters, numbers, and symbols you want to permit.

Why does the VBA code not run?

Make sure the code is in the correct worksheet's code window, the workbook is saved as an .xlsm file, and macros are enabled when the workbook opens.

Can these methods allow letters from languages other than English?

The supplied formula and VBA pattern allow only the English letters A–Z and the digits 0–9. To accept other alphabets, the permitted characters or the VBA pattern must be adjusted.


Related articles

Best Office Productivity Tools

🤖Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions…
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |  Round without Formula ...
Super Lookup: Multiple Criteria VLookup  |   Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |  Big Formula Bar   |  Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells   |  Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets:  12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!

All Kutools add-ins. One installer

Kutools for Office suite bundles add-ins for Excel, Word, Outlook & PowerPoint plus Office Tab Pro, which is ideal for teams working across Office apps.

ExcelWordOutlookTabsPowerPoint
  • All-in-one suite — Excel, Word, Outlook & PowerPoint add-ins + Office Tab Pro
  • One installer, one license — set up in minutes (MSI-ready)
  • Works better together — streamlined productivity across Office apps
  • 30-day full-featured trial — no registration, no credit card
  • Best value — save vs buying individual add-in