excel 4个字符排列组合
用excel把已有的4个字符串,排列产生4个字符串为一组的组合,不要重复的,具体如何操作,请教高手怎么做?...
用excel把已有的4个字符串,排列产生4个字符串为一组的组合,不要重复的,具体如何操作,请教高手怎么做?
展开
2个回答
展开全部
excel本身没有这个功能或者函数,用excel做一个自定义函数才能实现。
Sub TEST()
Dim MYAR As Variant, i As Integer, j As Integer, k As Double, p As Integer, q As Integer
Dim NumFree() As Boolean, TotalNum As Double, MyMtrx() As Integer
Dim MyFetch() As Integer
TotalNum = Application.WorksheetFunction.Permut(4, 4)
ReDim NumFree(1 To 4) '输入数字返回该数是否自由(未取)
ReDim MyMtrx(1 To TotalNum, 1 To 4)
ReDim MyFetch(1 To 4) '输入列号,返回该列应取数字
For i = 1 To 4
MyFetch(i) = i '初始化
Next i
For k = 1 To TotalNum
For i = 1 To 4 '列号
MyMtrx(k, i) = MyFetch(i)
Next i
NumFree(MyFetch(4)) = True '释放最末列的数字
For j = 4 - 1 To 1 Step -1 '从倒数第2列开始往前
NumFree(MyFetch(j)) = True '释放当前列
For i = MyFetch(j) + 1 To 4 '向下试探
If NumFree(i) Then
MyFetch(j) = i
NumFree(i) = False
For p = j + 1 To 4 '从当前列往后逐列从上往下找数
For q = 1 To 4 '数字从上往下找
If NumFree(q) Then
MyFetch(p) = q
NumFree(q) = False
Exit For
End If
Next q
Next p
Exit For
End If
Next i
If Not NumFree(MyFetch(4)) Then '最末列都取到数了,跳出
Exit For
End If
Next j
Next k
更多追问追答
追问
我是电脑小白,这个看不懂,用的是10版本,可以具体操作下吗?
追答
小白?好吧,我把代码放excel里面,你待会看附件。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询