Adding a symbol to the end of a string in each cell within a column

j4ttlife

New Member
Joined
Feb 2, 2022
Messages
30
Platform
  1. Windows
  2. MacOS
Hey guys, I was wondering if it's possible to add a symbol to each cell after the last character?

For example, my cells are currently in the format in the first picture.

I was hoping to add a * symbol in each cell at the end as in picture 2.

Thanks.
 

Attachments

  • pic1.jpg
    pic1.jpg
    75.2 KB · Views: 6
  • pic2.jpg
    pic2.jpg
    79.8 KB · Views: 6

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Forgot to mention that my spreadsheet is macro enabled. I'm okay with VBA but far from an expert. Was hoping to get some sort of an idea of how to code my request into the VB editor.
 
Upvote 0
Welcome to the Board!

Here is some VBA code that will create an interactive experience, where you can select the column you want to apply it to, and the character you want to add to the end:
VBA Code:
Sub MyInsertMacro()

    Dim col As String
    Dim cr As String
    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Prompt to ask which column to amend
    col = InputBox("Which column letter would you like to add character to?")
    
'   Prompt for character to add
    cr = InputBox("What character would you like to add to the end of each entry?")
    
'   Find last row with data in selected column
    lr = Cells(Rows.Count, col).End(xlUp).Row
    
'   Loop through all rows in selected column, starting on row 2
    For r = 2 To lr
'       If entry is not blank, add character to end
        If Cells(r, col) <> "" Then Cells(r, col) = Cells(r, col) & cr
    Next r
    
    Application.ScreenUpdating = False
    
End Sub
 
Upvote 0
Will it always be columns A & B?
 
Upvote 0
Yes, the columns will always be A and B.
Do you not like the interactive code I provided?
Do you want it to be hard-coded to ALWAYS use columns A and B, and ALWAYS use a "*"?
Will columns A and B ALWAYS end on the same row?
 
Upvote 0
In that case, another option
VBA Code:
Sub j4ttlife()
   With Range("A2", Range("B" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("if(@<>"""",@&""*"")", "@", .Address))
   End With
End Sub
 
Upvote 0
Solution
Do you not like the interactive code I provided?
Do you want it to be hard-coded to ALWAYS use columns A and B, and ALWAYS use a "*"?
Will columns A and B ALWAYS end on the same row?
Hi, I appreciate the answer you gave but I didn't need my code to be interactive. I have used the code provided by Fluff in another reply which works perfectly. Thanks for the help.
 
Upvote 0
In that case, another option
VBA Code:
Sub j4ttlife()
   With Range("A2", Range("B" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("if(@<>"""",@&""*"")", "@", .Address))
   End With
End Sub
This works perfectly, thank you!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,692
Members
449,117
Latest member
Aaagu

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