求阶乘、计算 vba

求阶乘、计算 vba,第1张

第一个

sub 求和()

dim arr, i as integer,he as integer

arr=[a3:b11]

for i=1 to ubound(arr)

    if arr(i,1)="1001" or arr(i,1)="1003" then 

        he=he+arr(i,2)

    end if

next

[b12]=he

end sub

第二个

Sub 阶乘()

 Dim i As Integer, a As Integer, jc As Integer

a = [a1]

jc = 1

For i = 1 To a

   jc = jc * i

Next

[a2] = jc

End Sub

在A1单元格输入整数,在B1单元格输出结果:

Sub 阶乘()

    Dim s As Long, n As Integer, i As Integer

    n = Val(Range("A1").Value)

    s = 1

    For i = 1 To n

        s = s * i

    Next i

    Range("B1").Value = s

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/10056024.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-04
下一篇2023-05-04

发表评论

登录后才能评论

评论列表(0条)

    保存