Skip to main content

Kutools for Office — One Suite. Five Tools. Get More Done.

How to delete string after nth character in Excel?

Author Sun Last modified

In Excel, you might often need to manipulate text strings by removing characters after a specific position. For example, you might want to truncate a string after the nth character to standardize data formats or clean up imported text. This task is common when working with identifiers, codes, or any text where only a fixed number of initial characters are required. Deleting content after the nth character helps prevent errors caused by extra data, ensures consistency for data import/export, or facilitates comparison and analysis. This guide will explore three practical techniques for removing characters after the nth character in a string: using formulas, Kutools for Excel, and VBA macros for automation. Each method offers advantages in particular scenarios, and you can select the approach best suited to your needs.

A screenshot demonstrating the result of deleting characters after the5th position using a formula in Excel

Remove all characters after the nth character with formula

Formulas offer a versatile way to handle text manipulation tasks in Excel, including removing characters after a specific position. This method is useful when you need a dynamic solution that adjusts automatically as your data changes. Here’s how you can use a formula to delete all characters after the nth character in a string:

Assuming you want to delete everything after the 5th character from the data in the following screenshot, here's how to handle it:

A screenshot showing an Excel sheet with strings for removing characters after the nth position

Select a blank cell and enter the following formula, press the "Enter" key and drag the "Fill Handle" of this result cell down to get the rest of the results.

=LEFT(A2,5)
A screenshot of the formula '=LEFT(A1,5)' applied to truncate text after the5th character in Excel
Tip: In the formula above, you can replace the number 5 with any other number to specify how many characters you want to keep. For example, changing it to 7 will remove all characters after the7th character in the text string.

This formula method is best used:

  • When you want a quick solution for trimming characters where the number of characters to keep is fixed.
  • If your data is stored in a table and you wish to keep the process transparent and reversible.
It’s less suitable when working with very large datasets or when you want to remove characters in-place (i.e., overwrite original data), since you’ll typically need to copy the results and paste over the original values as needed. Also, be mindful that formulas update dynamically: if the source cell changes, the result adjusts automatically.

 

Common issues and troubleshooting: If your data is shorter than the number you specify (for example, the cell has only 3 characters but you set 5), Excel will simply return the original string without error. However, if your data contains non-text values (formulas returning errors or numbers), ensure they are handled as needed before truncation. For array formulas or more dynamic needs, combine with other text functions (e.g., SEARCH, FIND) for more complex patterns.


Easily remove the specified number of characters after the nth character

"Kutools for Excel" offers a more user-friendly approach for removing characters after a certain position, especially useful when dealing with large datasets or when you prefer a tool-based solution. This method simplifies the task with just a few clicks. Here’s how you can use Kutools for Excel to achieve this:

Kutools for Excel offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Itegarate with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

After downloading and installing Kutools for Excel, go to the "Kutools" tab and select "Text" > "Remove by Position" to open the dialog box, then configure as follows:

  1. In the "Numbers" text box, enter the number of characters you want to remove.
    Tip: If you want to remove all characters after the nth character, you can enter a very large number, such as 999, to ensure that all characters following the nth character are removed.
  2. Select the "Specify Start Position" option, then enter the number representing the position from which you want to start removing characters.
    In this case, to remove characters after the 5th character, enter the number 6. This specifies that character removal will start from the 6th character.
  3. Click "OK".
    A screenshot of the Remove by Position dialog in Kutools for Excel configured to delete characters after the nth position
Result

Then, the specified number of characters after the 5th character will be removed from each cell in the selected range.

A screenshot showing the result after using Kutools for Excel to remove characters after the nth position

This solution is ideal in scenarios such as cleaning up large volumes of imported data, preparing lists where string length must be standardized, or when users are not familiar with writing Excel formulas or VBA. Kutools for Excel makes batch operations simple and broadens the possibilities for non-technical users.

Key advantages:

  • Batch operation on a selected range or the entire worksheet, saving manual effort for large data.
  • Intuitive and quick with minimal setup.
Limitations:
  • The operation overwrites original data, so it's recommended to back up your worksheet beforehand if you may need the unaltered content later.
  • Requires installation of an add-in, which may not be available in some IT-restricted environments.

Kutools for Excel - Supercharge Excel with over 300 essential tools. Enjoy permanently free AI features! Get It Now


VBA Macro – Automatically truncate text after the nth character across a range

When you need to automate the truncation of text after the nth character for multiple cells or large data sets – especially if this task will be performed regularly or in-place – a VBA macro can provide an efficient solution. This method is ideal for users comfortable with macros who require batch processing or want to streamline repetitive text-cleaning operations in Excel.

Typical applicable scenarios include:

  • Standardizing reference codes or IDs imported from other systems.
  • Automating recurring monthly text-processing tasks for reporting or data cleaning.
  • Batch editing where you wish to overwrite the original data instead of storing formula-based results elsewhere.
Advantages:
  • Process thousands of entries at once automatically.
  • Complete control over which range is affected and how many characters are kept.
  • Reusability for recurring tasks by running the macro again as needed.
Drawbacks:
  • Macros alter original data directly, so it's highly advisable to backup your worksheet before running.
  • To use the VBA code in the future, save the workbook in a macro-enabled format (.xlsm) and ensure that macros are enabled in Excel settings.

 

Operation steps:

  1. In Excel, click Developer > Visual Basic. This opens the Microsoft Visual Basic for Applications editor window.
  2. In the VBA editor, click Insert > Module. Copy and paste the following code into the new module:
    Sub TruncateTextAfterNthCharacter()
        Dim WorkRng As Range
        Dim cell As Range
        Dim n As Integer
        
        On Error Resume Next
        xTitleId = "KutoolsforExcel"
        
        Set WorkRng = Application.InputBox("Select the range to truncate:", xTitleId, Selection.Address, Type:=8)
        If WorkRng Is Nothing Then Exit Sub
        
        n = Application.InputBox("Keep how many characters (n)?", xTitleId, 5, Type:=1)
        If n < 1 Then Exit Sub
        
        For Each cell In WorkRng
            If Not IsEmpty(cell) And VarType(cell.Value) = vbString Then
                If Len(cell.Value) > n Then
                    cell.Value = Left(cell.Value, n)
                End If
            End If
        Next
    End Sub
  3. Close the VBA editor. Back in Excel, press Alt + F8, select "TruncateTextAfterNthCharacter", and click Run.
  4. A dialog will prompt you to select the range to process (e.g., A1:A10), and then to enter the number of characters to keep. After confirming, the macro will overwrite each selected cell with its truncated result.

Precautions and troubleshooting:

  • Always back up your data before running a macro. Macros like this one replace original content and cannot be undone with "Undo" (Ctrl+Z) after execution.
  • The macro only processes text values. If your range contains numbers, formulas returning numbers, or errors, these will not be changed. Modify the code to address other data types as needed.
  • If you see permission prompts about macros, enable macros in your Excel settings (File > Options > Trust Center > Trust Center Settings > Macro Settings).
  • To repeat the truncation on other ranges or worksheets, simply rerun the macro. You can assign the macro to a button for frequent reuse.
If you accidentally apply the macro to the wrong range or use the wrong truncation number, restore your backup or use version history features if available in your environment.

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 Toolsets12 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.

Excel Word Outlook Tabs PowerPoint
  • 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