[英]Excel Error #Value when executing VBA function
我建立了一个简单的函数来从字符串中收集一些值。 示例字符串为“ abc(1.1); abc(1.2); bac(1.3)”。 目标是获取值并在最后将它们求和并返回它们作为结果。 关于“勇气”(总和)的Msgbox效果很好,并显示正确的值。 但是使用此函数时,在单元格上出现#Value错误。 你能帮我理解为什么吗?
Function Organize(CellRef As String) As Double
Dim i As Integer
Dim lentotal As Long
Dim inicio As Long
Dim fim As Long
Dim a As Long
Dim valor As Double
Dim check As String
a = 1
x = CellRef
lentotal = Len(x)
i = Len(x) - Len(Replace(x, ";", ""))
Dim tech(1 To 100) As Double
Do While a <= i + 1
inicio = InStr(x, "(")
fim = InStr(x, ")")
'MsgBox Replace((Mid(x, inicio + 1, fim - inicio - 1)), ".", ",")
tech(a) = Replace((Mid(x, inicio + 1, fim - inicio - 1)), ".", ",")
If Left(x, 4) = "ABC" Then
valor = valor + tech(a)
End If
If a > i Then
MsgBox valor
Organize = valor
End
Else
x = Right(x, Len(x) - fim - 1)
End If
a = a + 1
Loop
End Function
尝试使用Exit Function
而不是End
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.