Replace last letter in column A using VBA

aaronr

New Member
Joined
Jul 8, 2010
Messages
34
I'm trying to replace the last letter in column A with out replacing any other letter using VBA.

Example - I'm trying to replace the last letter which is "A" in column A to be "B" with out changing any other letters

Column A
TAD106A
TAD107A
TAD108A
TAD109A
TA101A
TA102A
TA103A
TA104A
TA105A

<colgroup><col></colgroup><tbody>
</tbody>

Thanks for the help
 

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
Maybe this and copy down in adjacent column....no VBA

Code:
=SUBSTITUTE(A2,RIGHT(A2,1),"B",2)
 
Last edited:
Upvote 0
Give this a try. Copy to a standard module.

Requires the use of another column, I used column D. That D column can be changed to any other to suit your sheet, if it is now in use.

Howard

Code:
Option Explicit
Sub AARONR_A_B()
  Dim lRowCount&
 
  lRowCount = Cells(Rows.Count, "A").End(xlUp).Row - 1
  
  With Range("D2").Resize(lRowCount)
    .Formula = "=IF(RIGHT(A2,1)=CHAR(65),LEFT(A2,LEN(A2)-1)&""B"",A2)": .Value = .Value
    .Copy Range("A2")
  End With
  
  [D:D].ClearContents
  
End Sub
 
Upvote 0
L. Howard thanks for the code and works verify well. I'll added code delete that the whole column D when I'm done. Is there easy way to delete the whole Column D. Again thanks for your help.
 
Upvote 0
L. Howard thanks for the code and works verify well. I'll added code delete that the whole column D when I'm done. Is there easy way to delete the whole Column D. Again thanks for your help.
Here is a macro that does not involve any other columns...
Code:
[table="width: 500"]
[tr]
	[td]Sub ReplaceTrailingAwithB()
  Dim Addr As String
  Addr = "A1:A" & Cells(Rows.Count, "A").End(xlUp).Row
  Range(Addr) = Evaluate(Replace("IF(RIGHT(@)=""A"",LEFT(@,LEN(@)-1)&""B"",@)", "@", Addr))
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,214,432
Messages
6,119,468
Members
448,900
Latest member
Fairooza

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