当十进制符号为逗号时,函数返回错误2015

时间:2014-03-01 20:35:44

标签: excel vba

我在使用逗号作为十进制符号的系统下运行代码时遇到问题。如果有点(点)为十进制 - 我没有问题。 我的功能在一定时期内按客户计算营业额。日期作为星期和星期几存储在单个单元格中作为十进制数字。 是否有任何解决方案可以让我的函数使用两种十进制数格式?

以下是简化代码:

Sub Calculation()
    Dim Customer As String: Customer = "Customer1"
    Dim FromValue As Double: FromValue = 1.2 'week number 1 - Tuesday
    Dim ToValue As Double: ToValue = 6.4 'week number 6 - Thursday
    Debug.Print Formula1(Customer, FromValue, ToValue)
End Sub

Function Formula1(Customer As String, FirstDate, LastDate)
'Range ("G6:G100") contains quantity
'Range ("AD6:AD100") contains price per 1 piece
'Range ("A6:A100") contains customer's name
'Range ("K6:K100") contains week and day of week
Formula1 = Evaluate("=SumProduct(" & Range("G6:G100").Address & "," _
            & Range("AD6:AD100").Address & "," _
            & "--(ISNUMBER(FIND(" & Chr(34) & Customer & Chr(34) & "," & Range("A6:A100").Address & ")))," _
            & "--(" & Range("K6:K100").Address & ">=" & FirstDate & ")," _
            & "--(" & Range("K6:K100").Address & "<=" & LastDate & "))")
'=SumProduct($G$6:$G$100,$AD$6:$AD$100,--(ISNUMBER(FIND("Customer1",$A$6:$A$100))),--($K$6:$K$100>=1.2),--($K$6:$K$100<=6.4))
End Function

P.S。对不起我的英文

1 个答案:

答案 0 :(得分:0)

我自己找到了解决方案。问题出在数据类型中 - 如果FromValue和ToValue的数据类型是Double函数,则只能将点作为十进制。当我将数据类型更改为文本时 - 函数同时使用 - 逗号和点作为十进制符号。