Need to add a comma third from the right in a entire column

pack605

New Member
Joined
Dec 11, 2018
Messages
18
I have city and state in a column but need to add a comma after city and before state.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Welcome to Mr Excel,

Be better if you posted a 'small' sample of your data and what result you want to see.
 
Upvote 0
some vba

Code:
Sub t()
Dim c As Range
For Each c In Range("A1:A3") 'set range to actual
    c = Left(c.Value, Len(c) - 3) & ", " & Right(c.Value, 2)
Next
End Sub
 
Last edited:
Upvote 0
I have:
Revere MA
Manchester NH

needs to be:
Revere, MA
Manchester, NH
Assuming you want to do this directly in the existing cells, here is a macro that you can use (just change the three red F's to the actual column letter designation where your city/state values are located, change the blue 1 to the row number containing your first city/state value)...
Code:
[table="width: 500"]
[tr]
	[td]Sub AddCommaBeforStateAbbreviation()
  Dim Addr As String
  Addr = "[B][COLOR="#FF0000"]F[/COLOR][/B][B][COLOR="#0000FF"]1[/COLOR][/B]:[B][COLOR="#FF0000"]F[/COLOR][/B]" & Cells(Rows.Count, "[B][COLOR="#FF0000"]F[/COLOR][/B]").End(xlUp).Row
  Range(Addr) = Evaluate(Replace("IF(@="""","""",REPLACE(@,LEN(@)-2,0,"",""))", "@", Addr))
End Sub[/td]
[/tr]
[/table]

EDIT NOTE
---------------------------
If you want to do this in a different column, then you can use this formula...

=IF(F1="","",REPLACE(F1,LEN(F1)-2,0,","))

Change three F's and one 1 as indicated above.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,639
Messages
6,125,971
Members
449,276
Latest member
surendra75

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