2014-03-27 150 views
0

我需要做哪些計算公式的函數:如何使用SUM函數在VBA

Sigma(1/b^i) i...n 

它要求用戶填寫i和n

這是我到目前爲止:

b = InputBox("give your calue for b") 
n = InputBox("give your value for n") 

For i = 1 To n 

answer = (1/(b^i)) 


Next i 


MsgBox ("" & answer) 

目前它只給最後一次迭代。我如何將所有迭代添加到一起?

我希望有人能幫助我。

+0

嘗試'答案=答案+(1 /(B^I))' –

回答

0

可能像

dim i, b, n, answer 

b = InputBox("give your calue for b") 
n = InputBox("give your value for n") 

answer = 0 'initialization 

For i = 1 To n 

    answer = answer + (1/(b^i)) 

Next 

MsgBox (answer)