Split numbers from strings in Excel
In the process of working with Excel, I have encountered some cases that require separating only the fraction in a given string, now this post shares with you how to do this. The following article details how to separate numbers from a given string in Excel.
There are 2 ways to separate numbers:
- Case 1: Separate numbers from series and get positive values.
- Case 2: Separate numbers from series and take both positive and negative values.
1. Separate numbers from series and get positive values
Step 1: Open the Excel File to decompose -> Press the key combination Alt + F11 -> VBA window appears -> Go to the Insert tab -> Module .
Step 2: At the command prompt, enter the following code:
Function ExtractNumber (rCell As Range) Dim lCount As Long Dim sText As String Dim lNum As String sText = rCell For lCount = Len (sText) To 1 Step -1 If IsNumeric (Mid (sText, lCount, 1)) Then lNum = Mid (sText, lCount, 1) & lNum End If Next lCount ExtractNumber = CLng (lNum) End Function
Note: Remember this function name because when returning to Excel File must use it.
Step 3: After importing, click Save (because it contains a macro, when saving, display a message box, choose OK) -> Return to Excel File to find the function as shown:
Step 4: Copy the formula for the remaining cells with the following results:
2. Separate numbers from the string and take both positive and negative values
Step 1: Open the Excel File to decompose -> Press the key combination Alt + F11 -> VBA window appears -> Go to the Insert tab -> Module .
Step 2: At the command prompt, enter the following code:
Private Function SuperTrim (TheStr As String) Dim Temp As String, DoubleSpase As String DoubleSpase = Chr (32) & Chr (32) Temp = Trim (TheStr) Temp = Replace (Temp, DoubleSpase, Chr (32)) Do Until InStr ( Temp, DoubleSpase) = 0 Temp = Replace (Temp, DoubleSpase, Chr (32)) Loop SuperTrim = Temp End Function Public Function Tach_So (strText As String) Dim strText_1 As String Dim subText () As String, so () As Double Dim i As Integer, j As Integer, k As Integer, m As Integer strText = SuperTrim (strText) subText = Split (strText, "") For i = 0 To UBound (subText) For j = 1 To Len (subText (i) ) k = 0 If IsNumeric (Mid (subText (i), j, 1)) _ Or (Mid (subText (i), j, 1) = "-" And IsNumeric (Mid (subText (i), j + 1 , 1))) Then k = j Exit For End If Next j If k <> 0 Then m = m + 1 strText_1 = Val (Mid (subText (i),k)) ReDim Preserve so (1 To m) As Double so (m) = strText_1 End If Next i If index> 0 And index <= m Then Tach_So = so (m) Else Tach_So = "" End If End Function
Note: Remember the function name "" Tach_so () ".
Step 3: Click Save, just select OK . Return to the Excel file and select the Tach_so () function as shown:
Step 4: Tach_so () function has only one parameter that is the number of cells to split.
Step 5: Copy the formula for the remaining cells we have the results:
Thus separating both positive and negative values. And the negative sign in the first position of the cell is obtained.
Note: The above functions only apply to sequences that contain 1 string of consecutive numbers. If the data is a series of different numerical characters separated by alphabetic characters, the return value is the first numeric string.
Good luck!
You should read it
- 2 ways to separate column Full and Name in Excel
- Instructions for separating column content in Excel
- Instructions to stamp negative numbers in Excel
- How to concatenate strings in Excel
- PI (PI Function) in Excel - How to use PI numbers in Excel
- How to separate text strings by commas or spaces in Excel
- How to separate email from information in Excel
- How to extract numbers or text from Excel
- How to format numbers in Excel
- How to convert negative numbers to positive numbers Excel
- How to convert Apple Numbers documents to Microsoft Excel
- Instructions for cutting strings, concatenating strings in Excel
Maybe you are interested
Summary of functions that handle character strings in Excel, syntax and examples
The computer now finalizes the string, solving it in a flash
Write a program to reverse a string in Python
How to insert characters at the beginning or end of a string in Excel
How to separate text strings by commas or spaces in Excel
Instructions for cutting strings, concatenating strings in Excel