Removing last character in a cell, with varying word lengths

DataQuestioner

Board Regular
Joined
Sep 12, 2013
Messages
115
I need to remove the last character in a cell, which is always a "?" - the single words in each cell will have varying lengths, and can commence with a upper or lower case letter, and will contain any of the 26 letters of the alphabet, which could also include a hyphen, e.g.

"day-dream?" should become "day-dream"
"really?" should become "really"
"Unbelievably?" should become "Unbelievably".

I've tried experimenting with "IF" "LEFT" "RIGHT" and "MID" functions, but I haven't got my head around their proper usage yet!

Please help if you can.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
select cells with mouse ... press CTRL-H ... find what ? ... replace what leave blank ... replace all


enjoy
 
Upvote 0
select cells with mouse ... press CTRL-H ... find what ? ... replace what leave blank ... replace all
...
? is a wild-card, this process will blank all of the selected cells.
Search for ~? instead
 
Last edited:
Upvote 0
Guys,
Thanks for each of your suggestions...that was quick!

On reflection, I don't know why I didn't use the simple find/replace suggestion made by jsotola.

Thanks for your help.
 
Upvote 0
DataQuestioner,

Sample raw data in column A beginning in cell A1:


Excel 2007
A
1day-dream?
2really?
3Unbelievably?
4day-dream? really?
5??? DataQuestioner?
6? hiker95?
7
Sheet1


After the macro:


Excel 2007
A
1day-dream
2really
3Unbelievably
4day-dream? really
5??? DataQuestioner
6? hiker95
7
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Option Explicit
Sub RemoveLastCharacter()
' hiker95, 12/29/2013
' http://www.mrexcel.com/forum/excel-questions/747357-removing-last-character-cell-varying-word-lengths.html
Dim c As Range
For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
  c = Trim(c)
  If Right(c, 1) = "?" Then c = Left(c, Len(c) - 1)
Next c
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the RemoveLastCharacter macro.
 
Upvote 0

Forum statistics

Threads
1,215,477
Messages
6,125,036
Members
449,205
Latest member
Eggy66

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