Excel VBA常见问题:如何选取列内不重复资料?

2015-04-15 17:02 阅读 178 次 评论关闭

Excel VBA常见问题如何选取列内不重复资料

解答1:

Sub ff()
Dim aa As New Collection
cc = 2
On Error Resume Next
Do Until Cells(3, cc) = ""
   aa.Add Cells(3, cc).value, Cells(3, cc).Text
   cc = cc + 1
Loop
On Error GoTo 0
cc = 2
For Each itm In aa
   Cells(5, cc) = itm
   cc = cc + 1
Next
End Sub

解答2:提供一个以阵列方法为思考模式的方法

Sub ff()
On Error Resume Next
   cc = 2
   Set NoDupes = CreateObject("Scripting.Dictionary")
   Do Until Cells(3, cc) = ""
           NoDupes.Add Cells(3, cc).value, Cells(3, cc).value
       cc = cc + 1
   Loop
   Range("B6").Resize(1, UBound(NoDupes.keys) + 1) = NoDupes.keys        '阵列由0开始,所以+1
End Sub

版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!
转载请注明:Excel VBA常见问题:如何选取列内不重复资料? | 猎微网

评论已关闭!