Find & Replace Function, add one character end of string

DougStroud

Well-known Member
Joined
Aug 16, 2005
Messages
2,968
I have a column of cells that I need to add a character to all the ends of the string.
Can this be done w/ the Replace function, how?

Add the letter s to the end of every cell in the selected column.

Thanks,

Doug S.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
maybe this code will do

Code:
Sub AddS()
    Dim cl As Range
    For Each cl In Selection
        cl.Value = cl.Value & "s"
    Next cl

End Sub
 
Upvote 0
Thanks Roy,
I will definitely use your macro! But, I was hoping to see if my question was possible in the Replace Function w/in Excel itself, as I will do this very often.

So graciously, thank you.

But if anyone knows how to resolve my question in the original state, please advise.


Thanks,

Doug S.
 
Upvote 0
Doug, that code does exactly what you asked, perhaps you need to be more clear on what it is you want to do...the code provided will place on S at the end of every populated cell in a selection. To "hard" code the selection, for example, column H.

Sub AddS()
Dim cl As Range

Range("H:H").Select

For Each cl In Selection
If cl.Value <> "" Then cl.Value = cl.Value & "s"
Next cl

End Sub
 
Upvote 0
Right, I get it that this will do it, no problem.
But my follow up remark was that I know in the future I will need to perform the same type of replace, but w/ different character(s) and if I could do it as a part of Excel, rather than editing the macro each time, it would be somewhat easier to do and or manage....

Thanks for the reply....
hope that clarifys...(sp???) a bit more.


Thanks,

Doug S.

Ps.
Gibbs, I am preparing my sheet currently to review...
 
Upvote 0
Ahh, I see said the blind man, as he walked into a wall....

The below will make the macro dependent on cells in the worksheet, which you can enter the column letter for update and the replacement character...

Code:
Sub AddS()
Dim cl As Range
Dim col as variant
Dim rChar as variant

col = Range("A1") 'enter the column letter in this cell
rchar = Range("A2")  'enter your character in this cell

Range(col:col).Select

For Each cl In Selection
If cl.Value <> "" Then cl.Value = cl.Value & rchar
Next cl

End Sub
 
Upvote 0
Gibbs, that is just Bad to the Bone!

I am guessin here, but I need to tell the macro where and what, based on your post.
I inserted the macro and got an error:
First line: Sub AddS()
Am I supposed to enter the column here? If so, I got a message stating that this will reset....blah blah,
what do I do here?
 
Upvote 0
Doug, send me an IM later and I can walk you through it.

Yes, the code I gave you, modified from the original reply, designates cells A1 and A2 on the worksheet itself as identifying both the column letter you wish and the replacement text you wish respectively.

If you your code is running and you paste new code into the running module, you will get the "reset current project" error, so it is always a good idea to stop your current macro before making changes.

You said you wanted to add an S to a column, that was provided, then I made it specific to a column (H) which you could have changed to work as well, and then you wanted to have it be changeable, so that was provided.

If there is a not clear explanation of exactly what you want the code to do, it is more difficult to provide an adequate response, particularly if you are unable to make necessary modifications to the code you get to more suitable.

The more specific you are, the more specific code might be able to have provided.
 
Upvote 0

Forum statistics

Threads
1,214,396
Messages
6,119,268
Members
448,881
Latest member
Faxgirl

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