How to Extract Decimal Value from String in Excel


This tutorial will show you how to extract particular decimal values that are embedded within text strings in Microsoft Excel. It can be difficult to work with data that combines language and numbers, especially when you need to separate and extract particular numerical figures for additional research or calculations. Excel has a number of strong features and methods that can help you complete this task quickly.

Learning how to extract decimal values from strings will greatly improve your data manipulation abilities in Excel, whether you're working with financial data, product codes, or any other language that contains numeric information. You'll have a firm grasp of the methods and functions required to efficiently extract decimal values from strings in Excel by the end of this tutorial. Let's get started and utilise Excel's full potential to retrieve those elusive decimal numbers!

Extracting Decimal Value from String

Here, we will first create a VBA module and then run it to complete the task. So let us see a simple process to learn how you can extract decimal values from strings in Excel.

Step 1 : Consider an Excel sheet where you have a list of decimal strings similar to the below image.

First, use Alt + F11 to open the VBA application.

Step 2 :Then click on Insert, select Module, and copy the below code into the textbox.

Insert > Module > Copy.

Sub GetNumber()
    Dim xSRg As Range
    Dim xDRg As Range
    Dim xPRg As Range
    Dim xSRgArea As Range
    Dim xRgVal As String
    Dim xAddress As String
    Dim I As Long
    Dim K As Long
    Dim KK As Long
    On Error Resume Next
    xAddress = Application.ActiveWindow.RangeSelection.Address
    Set xSRg = Application.InputBox("Please select range:", "Extract Decimal Value", xAddress, , , , , 8)
    If xSRg Is Nothing Then Exit Sub
    Set xDRg = Application.InputBox("Select single cell:", "Extract Decimal Value", , , , , , 8)
    If xDRg Is Nothing Then Exit Sub
    Set xDRg = xDRg(1)
    For I = 1 To xSRg.Areas.Count
        Set xSRgArea = xSRg.Areas.Item(I)
        For K = 1 To xSRgArea.Count
            xRgVal = xSRgArea(K).Value
            KK = xSRgArea(K).Row - xSRg.Row
            If IsNumeric(xRgVal) Then
                xDRg.Offset(KK) = xRgVal - VBA.Fix(xRgVal)
            End If
        Next
    Next
End Sub

Step 3 :Then click F5 to run the module, select the range of cells containing the strings, and click Ok.

Step 4 :Then select a single cell where you need to place the result and click OK.

Conclusion

In this tutorial, we have used a simple example to demonstrate how you can extract decimal values from strings in Excel to highlight a particular set of data.

Updated on: 20-Jul-2023

157 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements