This post will guide you how to remove trailing commas from cell in Excel. How do I remove comma character at the end of a cell with a formula in Excel 2013/2016.
Table of Contents
1. Remove Trailing Commas using Formula
if you want to remove trailing commas from you Excel cells, and you can create a formula to check for a comma at the end of a string and then removes the final comma character. you can use the IF function, the RIGHT function, the LEFT function and the LEN function to remove the commas from each cell, like this:
=IF(RIGHT(A1,1)=",",LEFT(A1,LEN(A1)-1),A1)
You need to type this formula into a blank cell and press Enter key on your keyboard, and then drag the AutoFill handle over to the range of cells that you want to apply this formula.
2. Remove Last or Trailing Commas using User Defined Function with VBA Code
You can also use a user defined function with VBA code to remove last or trailing commas in Excel. Here are the steps to create and use such a function:
Step1: Press Alt + F11 to open the Visual Basic Editor.
Step2: In the Visual Basic Editor window, right-click on any sheet name and select Insert > Module.
Step3: In the code window, paste the following VBA code. Press Ctrl + S to save the workbook as a macro-enabled file (.xlsm).
Function RemoveLastComma_Excelhow(rng As Range) As String Dim s As String s = rng.Value If Right(s, 1) = "," Then s = Left(s, Len(s) - 1) End If RemoveLastComma_Excelhow = s End Function
Step4: Go back to the worksheet where you have the data with commas.
Step5: In an empty cell, enter the formula:
=RemoveLastComma_Excelhow(A1)
Where A1 is the cell that contains the comma-separated values.
Step6: press Enter key and you will see that the last or trailing comma is removed from each cell.
3. Video: Remove Last or Trailing Commas
In this video, you will learn how to use the LEFT and LEN functions to extract the text before the last comma, and how to create a User Defined Function with VBA code that can remove the trailing commas.
4. Related Functions
- Excel IF function
The Excel IF function perform a logical test to return one value if the condition is TRUE and return another value if the condition is FALSE. The IF function is a build-in function in Microsoft Excel and it is categorized as a Logical Function.The syntax of the IF function is as below:= IF (condition, [true_value], [false_value])…. - Excel LEFT function
The Excel LEFT function returns a substring (a specified number of the characters) from a text string, starting from the leftmost character.The LEFT function is a build-in function in Microsoft Excel and it is categorized as a Text Function.The syntax of the LEFT function is as below:= LEFT(text,[num_chars])…t)… - Excel RIGHT function
The Excel RIGHT function returns a substring (a specified number of the characters) from a text string, starting from the rightmost character.The syntax of the RIGHT function is as below:= RIGHT (text,[num_chars])… - Excel LEN function
The Excel LEN function returns the length of a text string (the number of characters in a text string).The syntax of the LEN function is as below:= LEN(text)…
Leave a Reply
You must be logged in to post a comment.