Forum Discussion

alex2476's avatar
alex2476
Copper Contributor
Mar 18, 2022

Number Extraction Excel

 

I have a cell with theses values:

14.19, 14.36, 20.22, 22.23A

 

I would like to have a formula that would  extract each of the numbers before the periods and eliminate whatever values are doubled.

 

So the content of the cell above would appear in another cell as:

14, 20, 22

 

I've looked at this article:

https://www.ablebits.com/office-addins-blog/2016/06/01/split-text-string-excel/

I'm not sure it applies because they are numbers and because I don't know how many values id have in the original cell. So in this example there are 4 values in the original cell and 3 in the result cell. But the first cell could have any number of values.

 

Any help is appreciated

  • Textsplit function is currently available to users running Beta Channel, Version 2203 (Build 15104.20004) or later on Windows and Version 16.60 (Build 22030400) or later on Mac.

    =LET(a,MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),b,CONCAT(IF(CODE(a)>64,"",a)),c,FLOOR(VALUE(TEXTSPLIT(b,", ")),1),TEXTJOIN(", ",,UNIQUE(INDEX(c,ROW(INDIRECT("1:"&SUM(FREQUENCY(c,c))))))))
    • alex2476's avatar
      alex2476
      Copper Contributor
      I don't know if i have the right version i just run the regular Office36. but ill take a look at that function.
  • alex2476 

    Here is a custom VBA function you can use:

    Function ExtractNum(s As String) As String
        Dim d As Object
        Dim a() As String
        Dim n As String
        Dim i As Long
        Set d = CreateObject(Class:="Scripting.Dictionary")
        a = Split(s, ", ")
        For i = 0 To UBound(a)
            n = Split(a(i), ".")(0)
            d(n) = Null
        Next i
        ExtractNum = Join(d.Keys, ", ")
    End Function

    With a value such as 14.19, 14.36, 20.22, 22.23A in cell A2, the formula

    =ExtractNum(A2)

    will return 14, 20, 22.

    The formula can be filled down if required.

    • alex2476's avatar
      alex2476
      Copper Contributor
      Ive tried the code above it works great!
      A collegue of mine has the french version of excel. it does not work on her computer. its the same document on a shared Gdrive . I assume that there is no french version of the vb language . but i dont know why she gets "#value" (#valeur in french).
      • alex2476 

        Does your colleague have a Mac? The macro that I posted will only work in the desktop version of Excel for Windows.

Resources