|
本帖最后由 qiao1019 于 2022-12-19 13:42 编辑
我先把数组导入到字典去重了然后再把字典提取出来了,但是当我想放到表里的时候报错了,请各位大佬帮忙看看哪里写错了。
Sub dict()
Dim arr, dic, n, xy, ky, x, y
Set dic = CreateObject("scripting.dictionary")
For Each ws In Worksheets
If ws.Name = "Map" Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
Next
Worksheets.Add.Name = "Map"
arr = Sheet1.Range([c18], [f18].End(xlDown)) '这个错在哪了?
For n = 1 To UBound(arr)
xy = arr(n, 3) & ":" & arr(n, 4)
dic(xy) = arr(n, 1)
Next
ky = dic.keys
bin = dic.items
For n = 1 To dic.Count
x = Split(ky(n - 1), ":")(0)
y = Split(ky(n - 1), ":")(1)
Worksheets("Map").Cells(x1, y1) = bin(n - 1) '这个错在哪了?
Next
End Sub
根据大佬提点,已解决
Sub dict()
t = Timer
Dim arr, dic, n, xy, ky, x, y
Set dic = CreateObject("scripting.dictionary")
For Each ws In Worksheets
If ws.Name = "Map" Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
Next
Worksheets.Add.Name = "Map"
With Sheet1
arr = .Range(.[c18], .[f18].End(xlDown))
End With
For n = 1 To UBound(arr)
xy = arr(n, 3) & ":" & arr(n, 4)
dic(xy) = arr(n, 1)
Next
ky = dic.keys
bin = dic.items
For n = 1 To dic.Count
x = Split(ky(n - 1), ":")(0)
y = Split(ky(n - 1), ":")(1)
Worksheets("Map").Cells(x * 1, y * 1) = bin(n - 1)
Next
Cells(x * 1, y * 1).Select
Selection.CurrentRegion.Cut [a1]
[a1].Select
Cells.ColumnWidth = 2
MsgBox Timer - t
End Sub
|
|