EXCEL自定义函数求1000以内的质数
时间:2023-08-22 15:29:16
自定义函数
=ZS(ROW(A1))
下拉
自定义函数代码
Function ZS(s%)
Dim f As Boolean, arr(), a%, i%
ReDim Preserve arr(1)
arr(0) = 2
For i = 3 To 999 Step 2
For j = 2 To i – 1
If i Mod j = 0 Then f = True: Exit For
Next
If Not f Then
a = a + 1
ReDim Preserve arr(a)
arr(a) = i
End If
f = False
Next
ZS = arr(s – 1)
End Function
宏代码
Sub getZS()
Dim arr(), f As Boolean
ReDim Preserve arr(1)
arr(0) = 2
For i = 3 To 999 Step 2
For j = 2 To i – 1
If i Mod j = 0 Then f = True: Exit For
Next
If Not f Then
a = a + 1
ReDim Preserve arr(a)
arr(a) = i
End If
f = False
Next
[c2].Resize(a, 1) = Application.Transpose(arr)
End Sub
标签:代码,函数,多个,自定义,Excel函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
如何修复u盘损坏?修复u盘损坏的4个方法介绍
2023-12-03 05:27:04
![](https://img.aspxhome.com/file/2023/6/a323739_0s.png)
win10桌面突然变成另一种状态怎么办?
2022-11-29 09:06:13
![](https://img.aspxhome.com/file/2023/30/a264437_0s.jpg)
PPT转换为word文档的方法
2022-10-05 13:20:03
Mac系统辅助键盘怎么开启? 辅助功能键盘设置方法
2022-11-07 19:56:03
![](https://img.aspxhome.com/file/2023/2/a214562_0s.jpg)
进入MAC Recovery Disk后如何打开Safari搜索友站里的信息
2022-07-12 00:12:25
![](https://img.aspxhome.com/file/2023/8/a215988_0s.jpg)
Win10系统接收不到更新通知怎么办?Win10系统接受不到更新通知解决方法
2023-12-09 01:35:03
![](https://img.aspxhome.com/file/2023/26/a219844_0s.png)
EXCEL表格忘记密码如何解决?EXCEL表格清除密码方法
2022-02-26 09:02:52
![](https://img.aspxhome.com/file/2023/4/a143704_0s.png)
wps怎么删除空格?
2023-06-16 05:36:50
![](https://img.aspxhome.com/file/2023/6/a169136_0s.gif)
升级Win10系统后为什么装不回Win7?
2023-12-20 03:11:34
![](https://img.aspxhome.com/file/2023/1/a277993_0s.jpg)
解决WPS 2007中文字换行的怪问题
2023-01-19 06:27:59
![](https://img.aspxhome.com/file/2023/2/a165022_0s.jpg)
2019年最佳Mac游戏,你玩过哪一款?
2022-03-27 03:30:54
![](https://img.aspxhome.com/file/2023/6/a210846_0s.jpeg)
带你详解Windows11是否会自动更新
2023-05-09 15:52:37
![](https://img.aspxhome.com/file/2023/1/a275775_0s.jpg)
Excel表格怎么制作简易号码抽签?
2022-02-01 15:09:55
![](https://img.aspxhome.com/file/2023/5/42495_0s.jpg)
Windows 10周年更新版正式发布!四条路升级
2023-01-27 01:36:07
![](https://img.aspxhome.com/file/2023/2/a288773_0s.jpg)
如何在WPS演示插入组织结构图?
2022-06-12 09:51:09
Win10系统更新怎么关闭 禁用自动更新的操作方法
2022-11-30 03:17:27
![](https://img.aspxhome.com/file/2023/3/a299478_0s.jpg)
Intel发布二代神经计算棒:16核心VPU 性能增8倍
2022-04-23 22:33:47
![](https://img.aspxhome.com/file/2023/2/a289645_0s.png)
Excel文件双击打不开怎么办?
2023-07-27 09:27:58
![](https://img.aspxhome.com/file/2023/1/42521_0s.jpg)
用Word制作拼音格子就是这么简单
2023-03-07 11:52:32
![](https://img.aspxhome.com/file/2023/5/24355_0s.png)
教你win10系统怎么禁用amd显卡驱动更新的方法
2022-02-05 17:29:49
![](https://img.aspxhome.com/file/2023/2/a289529_0s.gif)