Board logo

標題: 設計一個陣列相加可是得到的值一直是#VALUE [打印本頁]

作者: s100310424    時間: 2015-6-4 01:28     標題: 設計一個陣列相加可是得到的值一直是#VALUE

Function Madd(A As Variant, B As Variant)
Dim MC() As Variant
ReDim MC(LBound(A, 1) To UBound(A, 1), LBound(A, 2) To UBound(A, 2))
For i = LBound(A, 1) To UBound(A, 1)
For j = LBound(A, 2) To UBound(A, 2)
MC(i, j) = A(i, j) + B(i, j)
Next j
Next i
Madd = MC
End Function

上面是我的函數
而我在表單輸入{=Madd(A1:B2),(C1:D2))}----有使用ctrl+shifu+enter
大概是這樣
[attach]21099[/attach]
請問為什麼我讀不到A,B的值呢

請大家幫幫忙 感謝
作者: Scott090    時間: 2015-6-4 09:06

回復 1# s100310424


Function Madd(A1 As Variant, B1 As Variant)
Dim MC() As Variant,A,B
A=A1.value : B=B1.value
ReDim MC(LBound(A, 1) To UBound(A, 1), LBound(A, 2) To UBound(A, 2))
For i = LBound(A, 1) To UBound(A, 1)
For j = LBound(A, 2) To UBound(A, 2)
MC(i, j) = A(i, j) + B(i, j)
Next j
Next i
Madd = MC
End Function
作者: Scott090    時間: 2015-6-4 09:16

回復 1# s100310424

或者:
  1. Function Madd(A As Variant, B As Variant)
  2. Dim MC() As Variant
  3. A = A.Value: B = B.Value
  4. ReDim MC(LBound(A, 1) To UBound(A, 1), LBound(A, 2) To UBound(A, 2))
  5. For i = LBound(A, 1) To UBound(A, 1)
  6.     For j = LBound(A, 2) To UBound(A, 2)
  7.         MC(i, j) = A(i, j) + B(i, j)
  8.     Next j
  9. Next i
  10. Madd = MC
  11. End Function
複製代碼

作者: s100310424    時間: 2015-6-4 12:01

回復 3# Scott090

謝謝你~~~ 可以動作了,心感恩




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)