0

对于存款计算,我收到了 Excel 2010 VBA 函数实现的编译错误。我想返回一个数组,其中包含给定存款的利率及其值。

Function exe3djxInterestSelect(deposite)
  Dim V() As Variant
  ReDim V(1, 2)
  Select Case deposite
  Case Is < 0
    exe3djxInterestSelect = CVErr(xlErrNum)
  Case 0 To 1000
    V(1) = 0.055
    V(2) = deposite * 0.055
    exe3djxInterestSelect = V
  Case 1000 To 10000
    V(1) = 0.063
    V(2) = deposite * 0.063
    exe3djxInterestSelect = V
  Case 10000 To 100000
    V(1) = 0.073
    V(2) = deposite * 0.073
    exe3djxInterestSelect = V
  Case Else
    V(1) = 0.078
    V(2) = deposite * 0.078
    exe3djxInterestSelect = V
  End Select

结束功能

它返回#VALUE!.

它有什么问题?

谢谢

4

1 回答 1

1

您正在混合一维和二维数组:试试这个

Function exe3djxInterestSelect(deposite)
  Dim V() As Variant
  ReDim V(1 To 1, 1 To 2)
  Select Case deposite
  Case Is < 0
    exe3djxInterestSelect = CVErr(xlErrNum)
  Case 0 To 1000
    V(1, 1) = 0.055
    V(1, 2) = deposite * 0.055
    exe3djxInterestSelect = V
  Case 1000 To 10000
    V(1, 1) = 0.063
    V(1, 2) = deposite * 0.063
    exe3djxInterestSelect = V
  Case 10000 To 100000
    V(1, 1) = 0.073
    V(1, 2) = deposite * 0.073
    exe3djxInterestSelect = V
  Case Else
    V(1, 1) = 0.078
    V(1, 2) = deposite * 0.078
    exe3djxInterestSelect = V
  End Select
End Function
于 2013-02-08T17:33:04.330 回答