Delete Last Character If It Exists

dirk1965

Board Regular
Joined
Feb 18, 2004
Messages
241
Hi,

I'm new to this group and I have a question.

If a cells last character is a forward slash (/), how can you easily delete it via a cell formula? If the last character is not a forward slash (/) it makes no alterations.

Thanks
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
It's claiming I have too many arguments for the function. I'm trying to apply this to a whole column (like column C) if that helps.

Thanks
 
Upvote 0
hi. you can drag taht down!
or simplest way is to find/replace.
Copy that column to another column. then hightlight that
column. goto edit>replace "/" with ""
or you want to run a VBA .
 
Upvote 0
I cant use find/replace because there are several /'s in the cell. I only want to delete the / if its the last character in the cell.

Thanks
 
Upvote 0
ok!
Select the cells you want to remove the ending slash, then run this code!


<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> DelLastSlash()
<SPAN style="color:#00007F">Dim</SPAN> C <SPAN style="color:#00007F">As</SPAN> Range
Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN>

<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> C <SPAN style="color:#00007F">In</SPAN> Selection
    <SPAN style="color:#00007F">If</SPAN> Right(C.Value, 1) = "/" <SPAN style="color:#00007F">Then</SPAN>
        C.Value = Left(C.Value, Len(C.Value) - 1)
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">Next</SPAN> C
Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>

instalation:

1.right click on the sheet name.
2. in the right pane of the VBE paste the code.
3.Press Alt+F11
4. Highlight the cell in concern.
5.press alt+f8.
6. choose "DelLastSlash"
7. Click run!
8.done
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,712
Members
449,093
Latest member
Mnur

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