Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更正此vba代码?_Vba_Range - Fatal编程技术网

如何更正此vba代码?

如何更正此vba代码?,vba,range,Vba,Range,我还是vba新手 我试图创建一个新函数,但是,它不断给我一个我不期望的输出 我的代码如下: Function bonusplanA(a, b, c) Dim example As Range Set example = Range("a:c") Value = Application.WorksheetFunction.CountIf(example, ">=90") Value1 = Application.WorksheetFunction.Coun

我还是vba新手

我试图创建一个新函数,但是,它不断给我一个我不期望的输出

我的代码如下:

Function bonusplanA(a, b, c)

    Dim example As Range
    Set example = Range("a:c")

    Value = Application.WorksheetFunction.CountIf(example, ">=90")
    Value1 = Application.WorksheetFunction.CountIf(example, ">=80")

    If Value = 3 Then
      bonusplanA = "$20,000 bonus"
    Else
      If Value1 = 3 Then
      bonusplanA = "$10,000 bonus"
      Else
        bonusplanA = "NO BONUS"
      End If
    End If

End Function

您需要这样定义您的函数:

Function bonusplanA(a, b, c)

    If a >= 90 And b >= 90 And c >= 90 Then
        bonusplanA = "$20,000 bonus"
    Else
        If a >= 80 And b >= 80 And c >= 80 Then
            bonusplanA = "$10,000 bonus"
        Else
            bonusplanA = "NO BONUS"
        End If
    End If

End Function
您的示例中的问题是
Range(“a:c”)
不构成
a、b、c
变量的范围;而是选择由A、B和C列组成的范围

您需要直接使用参数
a
b
c
,而不是通过
范围
功能


否则,逻辑是正确的

你能详细说明一下你期望的产出和实际产出吗?好的,我正在解决一个问题,需要我陈述奖金计划。输出应为“20000美元奖金”、“10000美元奖金”或“无奖金”。但我一直得到0或#值。奖金计划取决于三个输入(a、b和c),如果三个输入都大于90,则为20000美元;如果三个输入都大于等于80,则为10000美元,否则不提供奖金。是的,这一部分很清楚。你需要描述的是:1。你在做什么输入;2.你期望得到什么样的输出(以及为什么)。a,b和c的输入是整数。但是我试着把a,b和c输入作为一个选择范围,从表中的任何地方。然而,我得到的结果是#有价值的!或0。