Excel VBA 全排列代码
(2012-07-28 16:15:52)
标签:
vbaexcel排列删除重复值杂谈 |
分类: VBA |
Option Explicit
Public resCol As Collection
'存放输出结果
Sub a()
Dim l As
Integer, irow As Long
Dim tmp As
String, t() As String, tt() As String
Dim i As
Integer, k As Integer, kk As Integer
Set resCol =
New
Collection
'初始化结果集合
irow =
ActiveSheet.Range("A65536").End(xlUp).Row
'取得数据的数量
kk = 1
''清理,准备输出结果
ActiveSheet.Range("$B:$B").ClearContents
For i = 1 To
irow
With ActiveSheet.Cells(i, 1)
tmp = .Value
l = Len(tmp)
ReDim t(1 To l) As
String
'初始化数组,将字符取出
For k = 1 To l
t(k) = Mid(tmp, k, 1)
Next
ReDim tt(1 To l)
Insert tt,
t
'排列
'输出结果
For k = i To resCol.Count
ActiveSheet.Cells(kk, 2).NumberFormatLocal = "@"
ActiveSheet.Cells(kk, 2).Value = resCol(k)
kk = kk + 1
Next
End With
Next
'删除重复值
ActiveSheet.Range("$B:$B").RemoveDuplicates Columns:=1,
Header:=xlNo
End Sub
Sub Insert(ByRef arr() As String, ByRef InsStr() As String)
'arr:排列结果 insstr:尚需进行排列的字符 全排列函数
Dim i As Integer
'循环变量
Dim j As Integer
Public resCol As Collection
Sub a()
End Sub
Sub Insert(ByRef arr() As String, ByRef InsStr() As String)
Dim i As Integer
Dim j As Integer