[英]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.