1

在 Excel 中调用Test1会为任何实数A和0 提供 0 B。为什么会出现这种情况?

Public Function Min(X As Double, y As Double, Optional y2 As Double, Optional y3 As Double) As Double
    Min = Application.WorksheetFunction.Min(X, y, y2, y3)
End Function


Function Test1(A As Double, B As Double)
    Test1 = Min(A, B)
End Function

在 Excel 中:=Test1(5,2).

4

1 回答 1

0

如果未传递给函数,可选参数将使用其默认值。对于双打,默认值为 0。如果您不提供y2y3本质上,您正在测试Application.WorksheetFunction.Min(A,B,0,0).

如果要更改默认值,可以执行以下操作:

Public Function Min(X As Double, y As Double, Optional y2 As Double = 10000000, Optional y3 As Double = 10000000) As Double
    Min = Application.WorksheetFunction.Min(X, y, y2, y3)
End Function

这使您y2的新内置人工最小值y3默认为哪个。10000000

于 2012-09-12T12:18:04.580 回答