从 excel 单元格错误中提取数字

Extract numbers from excel cell ERROR

我从这个社区找到了一个有用的公式,可以从 excel 个单元格中提取数字。

单元格示例为:

Theoretical pI: 9.53

公式为:

=VALUE(TRIM(LEFT(SUBSTITUTE(RIGHT(A4;LEN(A4)-FIND(":";A4));".";REPT(" ";LEN(A4));2);LEN(A4))))

然而公式返回的不是9,53而是196030!

谁能指出为什么会这样?

如果你有兴趣使用VBA,你可以使用这个功能或者忽略它。

    Public Function getNumber(fromThis As Range) As Double
        Dim retVal As String
        Dim ltr As String, i As Integer, european As Boolean

        retVal = ""
        getNumber = 0
        european = False

        On Error GoTo last
        If fromThis.Value Like "*.*,*" Then
            european = True
        End If

        For i = 1 To Len(fromThis)
            ltr = Mid(fromThis, i, 1)
            If IsNumeric(ltr) Then
                retVal = retVal & ltr
            ElseIf ltr = "." And (Not european) And Len(retVal) > 0 Then
                retVal = retVal & ltr
            ElseIf ltr = "," And european And Len(retVal) > 0 Then
                retVal = retVal & "."
            End If
        Next i
        getNumber = CDbl(retVal)
last:
    End Function