|
思路是如果有多个数字,
取使用次数最少的那个。
Sub test()
Set d = VBA.CreateObject("scripting.dictionary")
lr = Cells(Rows.Count, 1).End(3).Row
ar = Range("a1").Resize(lr)
ReDim br(1 To lr, 1 To 1)
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
t = Split(ar(i, 1), ",")
m = UBound(t)
If m > 0 Then
n = 10 ^ 6
For y = 0 To m
If d(t(y)) < n Then
n = d(t(y))
imin = t(y)
End If
Next
If d(imin) > 50 Then
MsgBox "第" & i & "行所有数字个数大于50"
Exit For
End If
br(i, 1) = imin
d(t(x)) = d(imin) + 1
Else
br(i, 1) = t(0)
d(t(x)) = d(t(0)) + 1
End If
End If
Next
Range("t1").Resize(lr) = br
Range("w2").Resize(d.Count, 2) = Application.Transpose(Array(d.keys, d.items))
Set d = Nothing
End Sub
填数.zip
(41.25 KB, 下载次数: 4)
|
评分
-
1
查看全部评分
-
|