1、首先在开发工具中打开VBA编辑器
2、在单元格区域当中输入一些内容作为例子
3、在VBA编辑器中插入模块
4、在模块当中输入如下代码,然后运行Function SumPro(a, b, opt坡纠课柩ions As String) &垆杪屑丝#39;根据下限和上限求累计和或者阶乘 If a <=0 Or b <=0 Then SumPro="只能输入自然数": Exit Function '限制参数为自然数 If a > b Then SumPro="下限不能超过上限": Exit Function Dim temp As Long If options="SUM" Then '如果参数是SUM则求和 For temp=a To b SumPro=SumPro+temp Next temp Else If options="PRO" Then '如果参数是PRO则求积 SumPro=1 For temp=a To b SumPro=SumPro * temp Next temp Exit Function End If SumPro="参数错误" '如果参数是两者之外则返回参数错误End IfEnd Function
5、在单元格B1中输入公式“=SumPro(1,10,"PRO")”,可得结果36288,即从1到10的数相乘,可以输入“=1*2*3*4*5*6*7*8*9*10”验证