Add a character to beginning and end of string

electrofunk

Board Regular
Joined
May 3, 2005
Messages
70
I need to add add a particular character (in this case, an asterix) to the beginning and end of a string of digits?

Currently looks like: 12345
Need it to look like: *12345*

Any suggestions?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I have to do the same thing to a bunch of cells at once sometimes, so I have these macros set to buttons. If you know how to use vba, then maybe this will help. If not, then ignore.

Code:
Sub Add_Text()
Dim r As Range
Dim addtext As String
On Error GoTo Canceled:

addtext = Application.InputBox _
                       (prompt:="Input the Text you'd like to add.", Type:=2)
30    If (addtext = "" Or addtext = "False") Then GoTo Canceled


For Each r In Selection
r.Value = r.Value & addtext

Next r

Canceled:

End Sub

Sub PredendText()
Dim r As Range
Dim addtext As String
On Error GoTo Canceled:

addtext = Application.InputBox _
                       (prompt:="Input the Text you'd like to add.", Type:=2)
30    If (addtext = "" Or addtext = "False") Then GoTo Canceled


For Each r In Selection
r.Value = addtext & r.Value

Next r

Canceled:

End Sub

One of em is for adding text to the beginning of the selected cells. The other is for adding text to the end of selected cells. Like I said, this is only useful if you find yourself adding the same text to a group of cells that already have information in them. And it's only useful if you know your way around macros.
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

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