Deleting Specific Capital Letters

Scubamil

New Member
Joined
Jul 27, 2017
Messages
1
I goofed! When I extracted First Names & Last Names from a string, it picked up the middle initial. How can I delete the last letter from a string ONLY if it's in caps? Here's an example of my data:

Anna
Anna
AnnaM
AnneB
AnneE
AnneG
Annette
AntonioL
April
AprilB
AprilD
AprilD
AprilM


<colgroup><col></colgroup><tbody>
</tbody>
I could just run the formula again that split the First and last names but this seemed like a challenge I might need to know the answer to at some point. Thanks all! Enjoy the Board....
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
First : welcome on the forum

Second : Here is the logic that you are searching

Code:
Sub DeleteMiddleLetter()
Dim r As Range

For Each r In Range("A:A")
'If last letter equal to is Ucase version
If Right(r, 1) = Right(UCase(r), 1) Then
    'Delete it
    r = Left(r, Len(r) - 1)
End If


Next
End Sub
 
Last edited:
Upvote 0
Using a function

=IF(ISNUMBER(MATCH(true, EXACT(RIGHT(A2, 1), CHAR(ROW($65:$90))), 0)), LEFT(A2, LEN(A2)-1), A2)

Which will need entered using Ctrl+Shift+Enter


 
Upvote 0
Here is another macro that you can try...
Code:
[table="width: 500"]
[tr]
	[td]Sub RemoveLastUpperCaseLetter()
  Dim Addr As String
  Addr = "A1:A" & Cells(Rows.Count, "A").End(xlUp).Row
  Range(Addr) = Evaluate(Replace("IF(@="""","""",IF(EXACT(RIGHT(@),UPPER(RIGHT(@))),LEFT(@,LEN(@)-1),@))", "@", Addr))
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Think about the formula method, it could be simplified to...

=LEFT(A2, LEN(A2)-ISNUMBER(MATCH(TRUE, EXACT(RIGHT(A2, 1), CHAR(ROW($65:$90))), 0)))

IF function eliminated.

Regards
 
Upvote 0
As a formula:

=LEFT(A1,MAX(1,LEN(A1)-EXACT(RIGHT(A1),UPPER(RIGHT(A1)))))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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