Insert a comma after first word
This tutorial shows how to insert a comma after the first word in a string through the use of the REPLACE, FIND and SUBSTITUTE functions, or VBA
=REPLACE(B5,(FIND(" ",B5)),0,",")
=REPLACE(B5,(FIND(" ",B5)),0,C5)
|
GENERIC FORMULA
=REPLACE(string,(FIND(" ",string)),0,",")
ARGUMENTS GENERIC FORMULA
=REPLACE(string,(FIND(" ",string)),0,comma_ref)
ARGUMENTS EXPLANATION This formula uses the REPLACE and FIND functions to insert a comma after the first word in a string. The FIND function is used to find the first occurrence of a space and the REPLACE function is used to replace the space with a comma and a space (, ).
Click on either the Hard Coded or Cell Reference button to view the formula that has the comma sign to be inserted directly entered into the formula or referenced to a specific cell that captures the comma sign.
In this example the formula will insert a comma after the first word in the selected cell, which is Exceldome. |
=SUBSTITUTE(B5," ",", ",1)
=SUBSTITUTE(B5," ",C5&" ",1)
|
GENERIC FORMULA
=SUBSTITUTE(string," ",", ",1)
ARGUMENTS GENERIC FORMULA
=SUBSTITUTE(string," ",", ",comma_ref)
ARGUMENTS EXPLANATION This formula uses the SUBSTITUTE function to insert a comma after the first word in a string.
With this formula you can enter the values, that will be returned if the cell is empty or not, directly into the formula or reference them to specific cells that capture these values.
Click on either the Hard Coded or Cell Reference button to view the formula that has the comma sign to be inserted directly entered into the formula or referenced to a specific cell that captures the comma sign.
In this example the formula will insert a comma after the first word in the selected cell, which is Exceldome. |
Dim ws As Worksheet
ws.Range("C5").Formula = "=Replace(B5,(Find("" "",B5)),0,"","")"
End Sub
Dim ws As Worksheet
ws.Range("D5").Formula = "=Replace(B5,(Find("" "",B5)),0,C5)"
End Sub
Dim ws As Worksheet
'insert a comma after first word in a string
For x = 5 To 8
ws.Range("C" & x).Formula = "=Replace(B" & x & ",(Find("" "",B" & x & ")),0,"","")"
Next x
End Sub
Dim ws As Worksheet
'insert a comma after first word in a string
For x = 5 To 8
ws.Range("D" & x).Formula = "=Replace(B" & x & ",(Find("" "",B" & x & ")),0,C5)"
Next x
End Sub
Dim ws As Worksheet
ws.Range("C5").Formula = "=Substitute(B5,"" "","", "",1)"
End Sub
Dim ws As Worksheet
ws.Range("D5").Formula = "=Substitute(B5,"" "",C5&"" "",1)"
End Sub
Dim ws As Worksheet
'insert a comma after first word in a string
For x = 5 To 8
ws.Range("C" & x).Formula = "=Substitute(B" & x & ","" "","", "",1)"
Next x
End Sub
Dim ws As Worksheet
'insert a comma after first word in a string
For x = 5 To 8
ws.Range("D" & x).Formula = "=Substitute(B" & x & ","" "",C5&"" "",1)"
Next x
End Sub
Related Topic | Description | Related Topic and Description |
---|---|---|
Insert a comma after each word | How to insert a comma after each word through the use of an Excel formula or VBA | |
Insert a comma before each word | How to insert a comma before each word through the use of an Excel formula or VBA | |
Insert a value before each word | How to insert characters before each word through the use of an Excel formula or VBA | |
Insert a value after each word | How to insert characters after each word through the use of an Excel formula or VBA |
Related Functions | Description | Related Functions and Description |
---|---|---|
FIND Function | The Excel FIND function returns the position of a specific sub-string within a string | |
SUBSTITUTE Function | The Excel SUBSTITUTE function replaces characters with another in a specified string |