gpt4 book ai didi

VBA 使用 for...next 计算 1*2*3...*n

转载 作者:行者123 更新时间:2023-12-04 21:08:34 25 4
gpt4 key购买 nike

我是VBA的初学者。我的问题是标题,我真的不知道如何更正代码。下面是我尝试的,但我认为这都是错误的......提前致谢。

Sub Try_Click()

Dim i As Integer
Dim n As Integer

n = ThisWorkbook.Sheets("Sheet 1").Cells(3, 2).Value

For i = 1 To n
i = i * (i + 1)

Next i

ThisWorkbook.Sheets("Sheet 1").Cells(5, 2) = i


End Sub

最佳答案

不改在循环:

Sub Try_Click()

Dim i As Long
Dim n As Long
Dim prod As Long

n = ThisWorkbook.Sheets("Sheet 1").Cells(3, 2).Value
prod = 1
For i = 1 To n
prod = prod * i
Next i

ThisWorkbook.Sheets("Sheet 1").Cells(5, 2) = prod
End Sub

关于VBA 使用 for...next 计算 1*2*3...*n,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50720924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com