Insertion of the word mobile after an _.

SeCreTEnDinG

New Member
Joined
Jan 6, 2014
Messages
9
Hi everyone,

Running Excel 2007 on WinXP.

I'm trying to figure out how to add the word mobile to a line of cells - A column - but the catch is that the words in the column are all written out_much_like_this. The word "mobile_" needs to be added after the first _ in each cell.

The result should look like out_mobile_much_like_this.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I need to stop doing this to myself, solved it.

The code is:

=SUBSTITUTE(A1, "_", "_mobile_", 1)

It will substitute any "_" it finds, but only the FIRST _ found in each text string located in A1. The replacement word is "_mobile_".
 
Upvote 0
I need to stop doing this to myself, solved it.

The code is:

=SUBSTITUTE(A1, "_", "_mobile_", 1)

It will substitute any "_" it finds, but only the FIRST _ found in each text string located in A1. The replacement word is "_mobile_".

That is not "code"... it's a formula and, as such, must be placed in a different column from the data. However, when you said...

"I'm trying to figure out how to add the word mobile to a line of cells - A column"

in your original message, it sounded like you wanted to physically change the original data values within the cells of Column A themselves, not show the changed value in another cell. If that is what you really wanted, you would need a macro, like this one (remember, if you run it, it will physically change the values in Column A directly)...

Code:
Sub PutWordAfterFirstUnderline()
  Dim Addr As String
  Const Word As String = "mobile"
  Addr = "A1:A" & Cells(Rows.Count, "A").End(xlUp).Row
  Range(Addr) = Evaluate("IF(LEN(" & Addr & "),SUBSTITUTE(" & Addr & ",""_"",""_" & Word & "_"",1),"""")")
End Sub

HOW TO INSTALL MACROs
------------------------------------
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (PutWordAfterFirstUnderline) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you are using XL2007 or above, and you want to retain this macro for use in the future, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0
That works even better without the copy / paste of values. Thanks Rick. It's been years since I've had to do any coding in Excels VB. Recently downloaded some books to start reading on my commute to hopefully help out on the board.

Cheers.
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,352
Members
449,080
Latest member
Armadillos

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