Excel中的排列 [英] Permutations in Excel

查看:123
本文介绍了Excel中的排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个6个空格的字符串,例如000000.每个空格可以保存三位数字之一,0,1或2.我知道我可以使用Excel中的Permut函数获得总共120个排列,即= PERMUT(6,3)= 120。但是我会实际上喜欢在单元格中具有每个单独的排列,例如000001,000010等。理想情况下,最终结果将是120行唯一的6位数字ID。



如果您不用手动输入数字就能获得更快的完成方式,请帮忙。



谢谢!

解决方案

在这个页面。将其复制到VBA模块中,然后在Excel中创建一列0到n的整数,其中n =您想要的ID数。在下一列中,使用第一列的值作为第一个参数调用VBA函数,将第三个参数作为第二个参数。一些像

 列A列b 
0 = baseconv(A1,3)
1 = baseconv A2,3)
2 = baseconv(A3,3)
...等

您的ID实际上只是使用基数3计数系统的增量值。您可以格式化输出以获得自定义格式为000000的前导零。



顺便提一下,使用6个位置和3个可用值,您可以获得3 ^ 6,或729唯一ID


I am have a string with 6 spaces, e.g. 000000. Each space can hold one of three digits - 0, 1, or 2. I know that I can get a total of 120 permutations using the Permut function in Excel, i.e. =PERMUT(6,3) = 120. But I would actually like to have each individual permutation in a cell, e.g. 000001, 000010, etc.. Ideally, the end result would be 120 rows of unique 6-digit IDs.

Please help if you know a faster way of accomplishing this without entering the figures manually.

Thanks!

解决方案

There is a VBA functionin the last post on this page. Copy it into a VBA module, then in Excel, create a column of integers from 0 to n where n = the number of IDs you want. In the next column, call the VBA function with the value from the first column as the first argument, and 3 as the second argument. Something like

Column A     Column b
0            =baseconv(A1, 3)
1            =baseconv(A2, 3)
2            =baseconv(A3, 3)
...          etc.

Your IDs are really just incremental values using a base 3 counting system. You can format the output to get leading zeros with a custom format of '000000'.

Incidentally, with 6 positions and 3 available values, you can get 3 ^ 6, or 729 unique IDs

这篇关于Excel中的排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆