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
- 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
May be interested
- How to split 1 cell into 2 cells in Excel - Split cells in Excelhow to split 1 cell into 2 cells in excel - split cells in excel. depending on different purposes, you want to split a cell into two cells to enter two different data in one cell and still be able to calculate normally as other cells.
- How to format numbers in Excelhow to format numbers in excel in the process of working, processing data in excel sometimes you need to format numbers in excel so that data can display the number format in accordance with the requirements to be processed. you do not know how to format numbers in ex
- How to split first and last names into 2 columns in Excelhow to split first and last names into 2 columns in excel. in the process of compiling data, sometimes you need to split the first name column into two first and last column columns to serve different purposes, for example, to sort the list by alpha b. thuthuatphanmem.vn will be directed.
- How to convert negative numbers to positive numbers Excelto convert negative numbers to positive numbers and vice versa on excel, you only need to perform a very simple operation.
- How to convert Apple Numbers documents to Microsoft Excelnumbers is spreadsheet software specifically for apple devices both on phones and on computers. basically, apple numbers works similar to microsoft excel, so you can completely convert documents between these two toolkits to serve each specific working situation.
- How to split cells, combine cells in Excelhow to split cells, combine cells in excel. on excel spreadsheets, many times you need to split cells, merge cells to fit the data you need to enter. you can combine two or more cells together using excel's built-in functions or use visual basic to merge
- Instructions for converting numbers to words in Excelto convert numbers to words in excel, you will use a support tool, instead of typing by hand, which is not accurate and takes a lot of time to do. below are some ways to convert numbers to words in excel.
- How to convert numbers into words in Excel?in excel, entering and typing amounts is very tiring, sometimes confusing. so why do this work faster but still have to ensure accuracy? tipsmake.com will introduce you to a support tool, or more accurately, an additional add-in for microsoft excel, very convenient for accounting, finance, people who have to work with big amounts ...
- How to round whole numbers in Excelhow to round whole numbers in excel in excel there are many mathematical functions used to round numbers. today software tips will guide you some functions that can be used to round whole numbers in excel.
- Do not round numbers in Excel, turn off rounding in Excelrounding numbers in excel is a handy function for calculating data, but sometimes it also makes you feel unnecessary troubles. to turn off the function of rounding in excel you can follow the following instructions