1

私はまだ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
4

1 に答える 1

2

次のように関数を定義する必要があります。

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 で構成される範囲が選択されます。

関数を介してではなく、 parameters をa直接使用する必要があります。bcRange

そうでなければ、論理は健全でした。:)

于 2013-03-03T20:48:39.510 に答える