我試圖通過簡單地總結A/B和B/C的外匯匯率並乘以找到A/C匯率的方法來計算交叉匯率,並且我一直得到0 。這是代碼:Excel VBA不斷返回0
Function forex(audData As Range, euData As Range)
a = Application.Count(audData)
e = Application.Count(euData)
'Counts how many values are in the data
aSum = 0
eSum = 0
aMean = 0
eMean = 0
For i = 1 To aud ' This sums the 1st forex rate and finds the mean
aSum = aSum + audData(i)
Next i
aMean = aSum/a
For i = 1 To eu ' This sums the 2nd forex rate and finds the mean
eSum = eSum + euData(i)
Next i
eMean = eSum/e
forex = (aMean * eMean)
End Function
這比OP想要做的更短更快,儘管他們仍然需要意識到使用未聲明的變量的危險,所以我會保留我更詳細的答案,儘管這顯然是優越的。 –
@JohnColeman,我同意 – user3598756
@ArenGallagher,你通過了嗎? – user3598756