Removing last specific character or characters

jamobe

New Member
Joined
Dec 23, 2014
Messages
36
Office Version
  1. 365
Platform
  1. Windows
Hi

I am using the following formula to remove a ";" from last character of a string if it exists

=IF(RIGHT(A1,1)=";",LEFT(A1,LEN(A1)-1),A1)

What I am struggling with is trying to nest this so that if the data had 2 semi colons it would also delete these

For example the data I have is as follows

EXAMPLE1;EXAMPLE1;EXAMPLE1

EXAMPLE2;EXAMPLE2;

EXAMPLE3;;

Is there a formula to remove the semi colons, at the end only and not to remove any other characters? Any help would be much appreciated!

Many Thanks

Jermaine
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Excel Formula:
=IF(RIGHT(A1,2)=";;",LEFT(A1,LEN(A1)-2),IF(RIGHT(A1,1)=";",LEFT(A1,LEN(A1)-1),A1))
 
Upvote 0
How about
Code:
=Substitute(A1,";","")

Should work for one or multiple occurences.
 
Upvote 0
In this case I only know how to do it with VBA macro.

VBA Code:
Public Function TestX(sTmp As String)
Dim x As Long
For x = Len(sTmp) To 1 Step -1
    If Mid(sTmp, x, 1) = ";" Then sTmp = Left(sTmp, x - 1) Else Exit For
Next x
TestX = sTmp
End Function

Excel Formula:
=TestX(A1)
 
Upvote 0
I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

This would allow for up to 5 semicolons at the end. Could be extended of course**. Depending on your Excel version, you may need to confirm this formula with Ctrl+Shift+Enter, not just Enter.

20 09 14.xlsm
AB
1abcabc
2abc;abc
3abc;;abc
4ab;cab;c
5a b;a b
6a;b;c;;a;b;c
7;a ;b ;c ;;a ;b ;c
8ab;;c;ab;;c
9a;;;;;b;;;;;c;;;;;a;;;;;b;;;;;c
Remove trailing semicolons
Cell Formulas
RangeFormula
B1:B9B1=LEFT(A1,LEN(A1)-SUM(--(RIGHT(A1,{1,2,3,4,5})=REPT(";",{1,2,3,4,5}))))



** If you have Excel 365 with the SEQUENCE() function then this would allow for any number of trailing semicolons.

Excel Formula:
=LEFT(A1,LEN(A1)-SUM(--(RIGHT(A1,SEQUENCE(LEN(A1)))=REPT(";",SEQUENCE(LEN(A1))))))
 
Last edited:
Upvote 0
If there is a maximum of 2 semicolons at the end then of course the post 2 suggestion should work fine, though it could be shortened a little to
Excel Formula:
=LEFT(A1,LEN(A1)-IF(RIGHT(A1,2)=";;",2,IF(RIGHT(A1,1)=";",1,0)))
 
Upvote 0
Wow, thanks for everyones help, Both Peter and Eduzs work exactly how I need it and will save both just in case I run into problems. Will update my profile on here also, I do have Excel 365. JLGwhiz, I tried this one and it removes all semicolons, not just the end ones unfortunately. Thanks again guys!
 
Upvote 0
Wow, thanks for everyones help
You're welcome. Glad we could help. :)

If there is a maximum of 2 semicolons at the end ... it could be shortened a little to
Excel Formula:
=LEFT(A1,LEN(A1)-IF(RIGHT(A1,2)=";;",2,IF(RIGHT(A1,1)=";",1,0)))
.. or further shortened to
Excel Formula:
=LEFT(A1,LEN(A1)-(RIGHT(A1,2)=";;")-(RIGHT(A1,1)=";"))
 
Upvote 0
Here is another array-entered** formula that will work for any number of trailing semi-colons...

=LEFT(A1,MAX(IF(MID(A1,ROW(INDEX(A:A,1):INDEX(A:A,LEN(A1))),1)<>";",ROW(INDEX(A:A,1):INDEX(A:A,LEN(A1))))))

**Commit this formula with CTRL+SHIFT+ENTER and not just Enter by itself
 
Upvote 0
RawTrim
EXAMPLE1;EXAMPLE1;EXAMPLE1EXAMPLE1;EXAMPLE1;EXAMPLE1
EXAMPLE2;EXAMPLE2;EXAMPLE2;EXAMPLE2
EXAMPLE3;;EXAMPLE3

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Trim = Table.AddColumn(Source, "Trim", each Text.TrimEnd([Raw], ";"))
in
    Trim
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,252
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top