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 .

Split numbers from strings in Excel Picture 1

Step 2: At the command prompt, enter the following code:

Split numbers from strings in Excel Picture 2

 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:

Split numbers from strings in Excel Picture 3

Step 4: Copy the formula for the remaining cells with the following results:

Split numbers from strings in Excel Picture 4

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 .

Split numbers from strings in Excel Picture 5

Step 2: At the command prompt, enter the following code:

Split numbers from strings in Excel Picture 6

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:

Split numbers from strings in Excel Picture 7

Step 4: Tach_so () function has only one parameter that is the number of cells to split.

Split numbers from strings in Excel Picture 8

Step 5: Copy the formula for the remaining cells we have the results:

Split numbers from strings in Excel Picture 9

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!

4.5 ★ | 2 Vote

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
    how 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
    how 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
    how 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 ExcelHow to convert negative numbers to positive numbers Excel
    to 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 ExcelHow to convert Apple Numbers documents to Microsoft Excel
    numbers 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
    how 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 ExcelInstructions for converting numbers to words in Excel
    to 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?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
    how 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 ExcelDo not round numbers in Excel, turn off rounding in Excel
    rounding 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