excel 中,A1~A9 填充9个数字。 通过运行宏,取6个数的组合。 填充在excel中。应该有84个组合。
请提供宏:
------最佳解决方案--------------------------------------------------------
Dim j As Long
Dim buff() As String
Dim l As Integer '排列长度
Dim ss As Variant '位置
Private Sub Make_CString(ByVal n As Long, ByVal ls As String)
Dim t As String
For i = n To 0 Step -1
t = ls & ss(i)
If Len(t) = l Then
Range("A" & j + 1) = t '存放找到的组合
buff(j) = t '存放找到的组合
j = j + 1
Else
Make_CString i - 1, t
End If
Next i
End Sub
Public Sub C排列()
Dim s As Variant, i As Long, t As Long
j = 1: l = 6
ss = Split("1,2,3,4,5,6,7,8,9", ",")
ReDim buff(1 To 84)
' Cells.ClearContents
Make_CString UBound(ss), ""
End Sub
运行后,A2-A85放的是1-9位置码组合,对应A1-A9,buff()中也是位置组合,根据位置,找到相应的数字就行了。
------其他解决方案--------------------------------------------------------
怎么会84啊
------其他解决方案--------------------------------------------------------
84个结果:
987654
987653
987652
987651
987643
987642
987641
987632
987631
987621
987543
987542
987541
987532
987531
987521
987432
987431
987421
987321
986543
986542
986541
986532
986531
986521
986432
986431
986421
986321
985432
985431
985421
985321
984321
976543
976542
976541
976532
976531
976521
976432
976431
976421
976321
975432
975431
975421
975321
974321
965432
965431
965421
965321
964321
954321
876543
876542
876541
876532
876531
876521
876432
876431
876421
876321
875432
875431
875421
875321
874321
865432
865431
865421
865321
864321
854321
765432
765431
765421
765321
764321
754321
654321
------其他解决方案--------------------------------------------------------
ss = Split("03,05,12,17,19,25,27,30,31", ",")
结果集返回如下,好像不对吗
313027
313025
313019
313017
313012
313005
313003
312725
312719
312717
312712
312705
312703
312519
312517
312512
312505
312503
311917
311912
311905
311903
311712
311705
311703
311205
311203
310503