Insert a value after first nth character
This tutorial shows how to insert a value after the first nth character through the use of an Excel formula, with the REPLACE function or VBA
=REPLACE(B5,3+1,0,"x")
=REPLACE(B5,C5+1,0,D5)
|
GENERIC FORMULA
=REPLACE(string,nth_char+1,0,value)
ARGUMENTS GENERIC FORMULA
=REPLACE(string,nth_char+1,0,value)
ARGUMENTS EXPLANATION This formula uses the REPLACE function to insert a specific value after the first nth character in a string.
Click on either the Hard Coded or Cell Reference button to view the formula that either has the value and the number that represents after which character to insert the value entered directly in the formula or referenced to cells.
In this example we are inserting a value of 'x' after the third (3rd) character from the left in a string captured in cell B5. |
Dim ws As Worksheet
ws.Range("C5").Formula = "=REPLACE(B5,3+1,0,""x"")"
End Sub
Dim ws As Worksheet
ws.Range("E5").Formula = "=REPLACE(B5,C5+1,0,D5)"
End Sub
Dim ws As Worksheet
'insert a specific value after the first nth character
ws.Range("C" & i).Formula = "=REPLACE(B" & i & ",3+1,0,""x"")"
Next i
End Sub
Dim ws As Worksheet
'insert a specific value after the first nth character
ws.Range("E" & i).Formula = "=REPLACE(B" & i & ",C" & i & "+1,0,D" & i & ")"
Next i
End Sub
Related Topic | Description | Related Topic and Description |
---|---|---|
Repeat a value n times in a cell | How to repeat a value n number of times in a cell through the use of an Excel formula or VBA |