我有一个新的小问题,尽管我确定这已经解决了,但是我找不到适合我问题的解决方案。
我有一个看起来像这样的数组:
ABCZZZZDEFGHGAAA
现在我只想缩小到每个字母一次:
ABCZDEFGH
它不需要按字母顺序排序或任何重要的事情(因为我想用它填充ListBox)不包含任何空值。所以没什么:
ABCZ____DEFGH____
我希望我的意思是可以理解的,您可以帮助我:)
答案 0 :(得分:1)
您可以使用字典轻松获得唯一值列表
Dim Uniques As Object
Set Uniques = CreateObject("Scripting.Dictionary")
For Each c In YourArray
If Not Uniques.exists(c) Then
Uniques.Add c, c
End If
Next c
YourListBox.List = Uniques.keys
答案 1 :(得分:0)
'Not sure if this is what you are looking for but this delete duplicates in column A
Option Explicit
Sub dupedelete()
Dim ws As Worksheet
Dim dict As Object
Dim lastrow As Long
Dim str As String
Set ws = Worksheets("Sheet1")
Set dict = CreateObject("Scripting.Dictionary")
lastrow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
Do While lastrow > 1
str = ws.Cells(lastrow, 1).Value
If dict.exists(str) Then
ws.Rows(lastrow).EntireRow.Delete
Else
dict.Add str, 0
End If
lastrow = lastrow - 1
Loop
Set dict = Nothing
End Sub