KutoolsforOffice — One Suite. Five Tools. Get More Done.February Sale: 20% Off

How to remove last/first character if it is a comma or certain character in Excel?

AuthorSiluviaLast modified

When working with data in Excel, it's common to encounter entries where the first or last character is a comma or another unwanted symbol. These situations often arise when exporting data from other systems, merging data sets, or after bulk editing textual information. Removing these stray characters can not only improve the appearance of your data, but also help prevent errors in subsequent analysis and operations, such as searching, matching, or importing to other systems.

This tutorial will guide you through several practical methods to quickly remove the last or first character—if it matches a specific symbol (such as a comma)—from multiple cells in Excel. You will find step-by-step instructions for both Excel formulas and Kutools for Excel utilities, along with additional scenarios and troubleshooting advice to help you choose the most suitable solution for your tasks.


Delete last/first character if it is a comma or certain character with formula

Excel formulas offer a straightforward way to remove an unwanted first or last character only if it matches a specific symbol from your cell values. This approach is especially useful when you want a dynamic solution and prefer not to install additional add-ins. You can use these formulas for data cleaning tasks on both small and large data sets, and they can be easily extended for use with different symbols by adjusting the parameters.

Delete the last character if it is a comma

To remove the last character from a cell only if it is a comma, follow these steps:

1. Choose a blank cell for your result—for example, D2. Enter the following formula into the selected cell and press Enter to confirm:

=IF(RIGHT(B2,1)=",",LEFT(B2,LEN(B2)-1),B2)

A screenshot of Excel showing a formula to remove the last character if it's a comma

2. Drag the fill handle (a small square at the bottom-right corner of the cell) down to apply the formula to other cells in the list. Each cell will display the text with the last comma removed, only if the last character actually is a comma.

Delete the first character if it is a comma

To remove the first character if it is a comma, use the following method:

1. Select a blank cell (for instance, D2 if your data starts in B2) and enter this formula:

=IF(LEFT(B2,1)=",",RIGHT(B2,LEN(B2)-1),B2)

A screenshot of Excel showing a formula to remove the first character if it's a comma

2. After pressing Enter, copy the formula down as needed to cover your data range. The formula will return the cell value without the leading comma if it finds one.

Note: In both formulas, "B2" refers to the cell you wish to inspect and process, and "," is the symbol to be removed. If you need to target another symbol, such as a semicolon or a dash, replace the comma in the formula accordingly. If your data starts in another column or row, adjust the cell references to match.

Practical tips: These formula-based solutions are best suited for situations where you need to keep the original data intact and output the cleaned data to a separate column. If you want to remove other characters, simply change the character within the quotes in your formula. Remember to check for data inconsistencies before applying the formulas to a large data set, as formulas will only remove the specified symbol and will not affect other unwanted characters.

Error reminder: If your cells are empty or contain only one character (for example, a single comma), the formula may return an empty string. This is expected, but you should be aware when reviewing your results.


Delete last/first character if it is a comma or certain character with Kutools for Excel

If you are working with large data sets and want to simplify the process of detecting and removing unwanted first or last characters, Kutools for Excel provides practical utilities that can help you accomplish this task efficiently. Using Kutools' Select Specific Cells and Remove by Position features allows you to identify and clean up your data without building complex formulas or manually searching for issues. This is particularly useful when you need to clean a wide range of cells in-place, and is ideal for users with intermediate Excel skills or those seeking time-saving automation.

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

1. Select all cells in your target range that may begin or end with the character you want to assess. Then, click Kutools > Select > Select Specific Cells from the Kutools menu.

A screenshot of Kutools for Excel's Select Specific Cells option

2. In the Select Specific Cells dialog box, configure the options as follows for precise selection:

2.1) Under Selection type, choose Cell to focus on individual cells.
2.2) In Specific type, use the drop-down to pick either Ends with or Begins with, depending on whether you want to remove the trailing or leading character.
2.3) Enter the character you want to detect, such as a comma (,) or another symbol, into the textbox.
2.4) Press OK to apply your settings.
Once the dialog confirms how many cells match your criteria, click OK again. The relevant cells will be automatically selected on your worksheet.

A screenshot of Kutools for Excel's Select Specific Cells dialog

3. With the appropriate cells selected, click Kutools > Text > Remove by Position to open the removal utility.

A screenshot of Kutools for Excel's Remove by Position option

4. In the Remove by Position dialog box, configure the settings to remove only the specific character. Type 1 in the Numbers box to indicate only the first or last character should be removed. Choose From right to remove the last character, or From left to remove the first character. Make your selection, then click OK to apply the changes.

A screenshot of Kutools for Excel's Remove by Position dialog

Now, the unwanted character at the beginning or end of your selected cells will be removed instantly.

Tip: This operation will directly modify your original data, so if you'd like to keep a copy of the initial content, consider duplicating your column before starting. Kutools' approach is especially helpful if your selection includes hidden rows or filterable results, as the tools work reliably on visible cells.

Precaution: Double-check that you have correctly selected all target cells prior to using the Remove by Position tool, to avoid accidental data modifications.

If you encounter issues where not all characters are removed as expected, ensure your selection matches the character you input. Also, confirm that there are no leading/trailing spaces, which may affect detection accuracy.

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


Delete last/first character with VBA code

For users seeking to automate this cleaning task across a variable range, using VBA (Visual Basic for Applications) code can provide a flexible solution. The VBA method is suitable when you need to process multiple sheets, large data sets, or prefer a reusable macro for future use. VBA code enables you to remove the first or last character only if it matches a specified symbol such as a comma, semicolon, or other.

1. To begin, click Developer Tools > Visual Basic. In the Microsoft Visual Basic for Applications window that appears, go to Insert > Module.

2. Copy and paste the following VBA code into the Module:

Sub RemoveFirstOrLastIfChar()
    Dim WorkRng As Range
    Dim Rng As Range
    Dim xTitleId As String
    Dim RemoveChar As String
    Dim PositionType As String
    
    On Error Resume Next
    xTitleId = "KutoolsforExcel"
    
    Set WorkRng = Application.Selection
    Set WorkRng = Application.InputBox("Select Range to clean", xTitleId, WorkRng.Address, Type:=8)
    
    RemoveChar = Application.InputBox("Character to remove (e.g. , or ;)", xTitleId, ",", Type:=2)
    
    PositionType = Application.InputBox("Remove from (Enter 'Left' or 'Right')", xTitleId, "Right", Type:=2)
    
    Application.ScreenUpdating = False
    
    For Each Rng In WorkRng
        If PositionType = "Right" Then
            If Right(Rng.Value, 1) = RemoveChar Then
                Rng.Value = Left(Rng.Value, Len(Rng.Value) - 1)
            End If
        ElseIf PositionType = "Left" Then
            If Left(Rng.Value, 1) = RemoveChar Then
                Rng.Value = Right(Rng.Value, Len(Rng.Value) - 1)
            End If
        End If
    Next
    
    Application.ScreenUpdating = True
End Sub

3. To run the code, click the Run button button in the VBA editor. When you execute the macro, Excel will prompt you to select the range to clean, input the target character (such as a comma), and specify from which side ("Left" or "Right") to remove it.

The code will quickly review each cell in your chosen range and remove the first or last character where it matches your input. The macro is designed to skip cells that do not have the specified symbol at the chosen position, helping ensure you do not lose unintended data.

Practical tip: You may want to save your workbook before running the macro, especially if applying changes to a large data range or important data. Macros can be customized to operate on specific sheets, or enhanced to process multiple characters if needed.

Error reminder: Always ensure you enter the character exactly as it appears in your data, and carefully select "Left" or "Right" during processing. Inputs are case-sensitive and must match cell contents exactly.

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.

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