从这个社区,我发现了一个从excel细胞中提取数字的有用公式。
单元格的一个例子是:
理论pI:9.53
公式是:
=VALUE(TRIM(LEFT(SUBSTITUTE(RIGHT(A4;LEN(A4)-FIND(":";A4));".";REPT(" ";LEN(A4));2);LEN(A4))))
然而,返回的公式不是9,53而是196030!
有人能指出为什么会这样吗?
答案 0 :(得分:0)
如果您有兴趣使用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