Excel数字排列组合公式写法介绍
时间:2023-04-05 08:00:36
文章通过一个实例来介绍数字排列组合公式的写法,感兴趣的朋友对排列组合公式稍微变通实现类似的需求。
需要排列组合公式的,多是对数字感兴趣的朋友,喜欢对数字排列组合。
本文介绍通过excel中编写VBA代码,掌握一些规律和算法来写排列组合公式。
数字排列组合公式的思路,可以这样理解:从n个不同元素中,任取m(m≤n)个元素按照一定的顺序排成一列。
下面通过一个实例来讲解如何通过排列组合公式完成数字排列组合。
比如从"9876543"中任意取5个数来进行排列组合,方法是:
新建一个工作表,按ALT+F11,打开VBE编辑器,插入——模块,在右边代码编辑框复制下面的代码,然后单击工具栏的“运行”命令,然后切换到工作表中,可以看见A列已经根据排列组合公式自动生成了所需要的所有数字排列组合。
Sub 排列组合公式()
Dim II%, I%, J%, K%, L%, M%
Dim Srt1$, Srt2$, Srt3$, Srt4$, Srt5$
Dim TStr1$, TStr2$, TStr3$, TStr4$
Dim t, arr()
Const FullStr = "9876543"
t = Timer
II = 0
For I = 1 To 7
Srt1 = Mid(FullStr, I, 1)
TStr1 = Replace(FullStr, Srt1, "")
For J = 1 To 6
Srt2 = Mid(TStr1, J, 1)
TStr2 = Replace(TStr1, Srt2, "")
For K = 1 To 5
Srt3 = Mid(TStr2, K, 1)
TStr3 = Replace(TStr2, Srt3, "")
For L = 1 To 4
Srt4 = Mid(TStr3, L, 1)
TStr4 = Replace(TStr3, Srt4, "")
For M = 1 To 3
Srt5 = Mid(TStr3, M, 1)
II = II + 1
ReDim Preserve arr(1 To II)
arr(II) = Srt1 & Srt2 & Srt3 & Srt4 & Srt5
Next
Next
Next
Next
Next
Range("A1:A" & II) = Application.Transpose(arr)
End Sub
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
win10控制面板怎么打开?
![](https://img.aspxhome.com/file/2023/4/a304932_0s.png)
科普:关于图像格式JPG和JPEG你知多少?
![](https://img.aspxhome.com/file/2023/6/a325770_0s.jpg)
Excel中的文字如何上下居中对齐
![](https://img.aspxhome.com/file/2023/7/a153797_0s.png)
Word2010文档自动生成目录和更新目录方法
谷歌浏览器打开是2345怎么改回来?亲测有效!
![](https://img.aspxhome.com/file/2023/7/a327280_0s.png)
使用u深度装win10后声音忽大忽小该怎么办?
![](https://img.aspxhome.com/file/2023/28/a244719_0s.jpg)
纸质文字转换成电子版文字的技巧 纸质转换电子版
![](https://img.aspxhome.com/file/2023/1/15411_0s.jpg)
wps表格输入日期
Excel表格中大量手机号码如何批量查询归属地
![](https://img.aspxhome.com/file/2023/5/a141785_0s.jpg)
Win10搜索框太大怎么缩小?
![](https://img.aspxhome.com/file/2023/1/a282975_0s.jpg)
PPT图片进行旋转
![](https://img.aspxhome.com/file/2023/10/a352181_0s.jpg)
鲁大师怎么屏蔽广告弹窗
![](https://img.aspxhome.com/file/2023/9/a341611_0s.png)
8个好用的屏幕录制软件,看看哪款适合你?
![](https://img.aspxhome.com/file/2023/4/a207594_0s.jpeg)
Win10菜单想要改成Win7开始菜单样式怎么改?
![](https://img.aspxhome.com/file/2023/26/a221721_0s.png)
win10装机版和纯净版哪个好
![](https://img.aspxhome.com/file/2023/1/a282289_0s.jpg)
ppt怎么把图片融入背景?
![](https://img.aspxhome.com/file/2023/10/a350584_0s.png)
word文档编辑受限制怎么解除?word文档编辑受限解除教程
![](https://img.aspxhome.com/file/2023/1/a273621_0s.jpg)
希捷发布最强14TB硬盘:美联邦认证安全加密
![](https://img.aspxhome.com/file/2023/4/a306809_0s.jpg)
Win7电脑系统资源占用情况该如何查看?
![](https://img.aspxhome.com/file/2023/3/a294684_0s.jpg)
excel中显示日期和星期的方法
![](https://img.aspxhome.com/file/2023/5/42885_0s.jpg)