简化数据处理,掌握Excel去除空格的高效技巧
532
2022-12-02
EXCEL自定义函数求1000以内的质数
自定义函数
=ZS(ROW(A1))
下拉
自定义函数代码
Function ZS(s%)Dim f As Boolean, arr(), a%, i%ReDim Preserve arr(1)arr(0) = 2For i = 3 To 999 Step 2For j = 2 To i – 1If i Mod j = 0 Then f = True: Exit ForNextIf Not f Thena = a + 1ReDim Preserve arr(a)arr(a) = iEnd Iff = FalseNextZS = arr(s – 1)End Function
宏代码
Sub getZS()Dim arr(), f As BooleanReDim Preserve arr(1)arr(0) = 2For i = 3 To 999 Step 2For j = 2 To i – 1If i Mod j = 0 Then f = True: Exit ForNextIf Not f Thena = a + 1ReDim Preserve arr(a)arr(a) = iEnd Iff = FalseNext[c2].Resize(a, 1) = Application.Transpose(arr)End Sub
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。