Insert a comma after first number
This tutorial shows how to insert a comma (,) after the first number in a cell through the use of an Excel formula, with the REPLACE, MIN, MID and FIND functions or VBA
EXCEL FORMULA 1. Insert a comma after first number in a cell using the REPLACE, MIN, MID and FIND functions
EXCEL
|
GENERIC FORMULA
=REPLACE(string,MIN(FIND({0,1,2,3,4,5,6,7,8,9},string&"0123456789"))+1,1,","&MID(string,MIN(FIND({0,1,2,3,4,5,6,7,8,9},string&"0123456789"))+1,1))
ARGUMENTS GENERIC FORMULA
=REPLACE(string,MIN(FIND({0,1,2,3,4,5,6,7,8,9},string&"0123456789"))+1,1,comma&MID(string,MIN(FIND({0,1,2,3,4,5,6,7,8,9},string&"0123456789"))+1,1))
ARGUMENTS EXPLANATION This formula uses the REPLACE, MIN, MID and FIND functions to insert a comma after the first number in a cell.
Click on either the Hard Coded or Cell Reference button to view the formula that either has the comma directly entered in the formula or referenced to a cell that captures the value that is to be inserted after a first number in a string.
In this example we are adding a comma after the first number captured in cell B5, which is number 4. |
Dim ws As Worksheet
ws.Range("C5").Formula = "=REPLACE(B5,MIN(FIND({0,1,2,3,4,5,6,7,8,9},B5&""0123456789""))+1,1,"",""&MID(B5,MIN(FIND({0,1,2,3,4,5,6,7,8,9},B5&""0123456789""))+1,1))"
End Sub
Dim ws As Worksheet
ws.Range("D5").Formula = "=REPLACE(B5,MIN(FIND({0,1,2,3,4,5,6,7,8,9},B5&""0123456789""))+1,1,C5&MID(B5,MIN(FIND({0,1,2,3,4,5,6,7,8,9},B5&""0123456789""))+1,1))"
End Sub
Dim ws As Worksheet
'insert comma after the first number in a cell by looping through each cell in a specified range
ws.Range("C" & x).Formula = "=REPLACE(B" & x & ",MIN(FIND({0,1,2,3,4,5,6,7,8,9},B" & x & "&""0123456789""))+1,1,"",""&MID(B" & x & ",MIN(FIND({0,1,2,3,4,5,6,7,8,9},B" & x & "&""0123456789""))+1,1))"
Next
End Sub
Dim ws As Worksheet
'insert comma after the first number in a cell by looping through each cell in a specified range
ws.Range("D" & x).Formula = "=REPLACE(B" & x & ",MIN(FIND({0,1,2,3,4,5,6,7,8,9},B" & x & "&""0123456789""))+1,1,C5&MID(B" & x & ",MIN(FIND({0,1,2,3,4,5,6,7,8,9},B" & x & "&""0123456789""))+1,1))"
Next
End Sub
Related Topic | Description | Related Topic and Description |
---|---|---|
Insert a comma before first number | How to insert a comma (,) before the first number in a cell through the use of an Excel formula or VBA | |
Insert comma to end of a cell | How to add a comma (,) to the end of a cell through the use of an Excel formula or VBA | |
Insert a comma after first word | How to insert a comma after the first word in a string 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 |
Related Functions | Description | Related Functions and Description |
---|---|---|
MIN Function | The Excel MIN function returns the smallest value from a specified range of numeric values | |
MID Function | The Excel MID function returns the specified number of characters from a selected string, starting at a specified position | |
FIND Function | The Excel FIND function returns the position of a specific sub-string within a string |