How to remove comma from end of Google Sheets cell if it ends with a comma?
Asked Answered
M

3

6

How to automatically trim a comma off? So I don't have to remove it manually?

Messiah answered 12/4, 2019 at 23:24 Comment(0)
S
12

you can use regex for that like this:

=REGEXREPLACE(A1, ",$", )

0

Sherlocke answered 12/4, 2019 at 23:34 Comment(3)
what does ,$ mean?Messiah
it means: "remove comma if a comma is at the far end"Sherlocke
not rly sure what you asking about... REGEXREPLACE is like a SUBSTITUTE formula, but more flexible. SUBSTITUTE can work with only what is present in cell while REGEXREPLACE can work with additional parameters like $ in this case which can be translated as "from end" (^ would be "from begining" so if you would had cell like ,a, b, then you could do =REGEXREPLACE(A1, "^,|,$", )) where | means "and")Sherlocke
M
2
=IF(RIGHT(B2,1)=",",LEFT(B2,LEN(B2)-1),B2)

Using IF and LEN.

If the last character of a cell value is a comma, then the answer should be the length of the cell minus the last character (the comma)

If the last character is not a comma, just pass the original value.

Messiah answered 12/4, 2019 at 23:26 Comment(0)
S
-1

Substitute works pretty well..it allows you to select which occurence

=SUBSTITUTE(L2,",","")

Google Sheets Substitute function

Shirker answered 14/4, 2020 at 1:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.