|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 排序()
Dim ar As Variant, br As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
With Sheets("排序依据")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "排序依据为空!": End
ar = .Range("a1:a" & r)
End With
With Sheets("员工表")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(1, Columns.Count).End(xlToLeft).Column
If rs < 2 Or y < 2 Then MsgBox "员工表为空!": End
br = .Range(.Cells(1, 1), .Cells(r, y))
End With
For j = 1 To UBound(br, 2)
If br(1, j) <> "" Then
d(br(1, j)) = ""
End If
Next j
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
If d.exists(ar(i, 1)) Then
m = m + 1
dc(ar(i, 1)) = m
End If
End If
Next i
Dim cr()
ReDim cr(1 To UBound(br), 1 To UBound(br, 2))
For i = 1 To UBound(br)
If br(i, 1) <> "" Then
n = n + 1
For j = 1 To UBound(br, 2)
lh = dc(br(1, j))
If lh <> "" Then
cr(n, lh) = br(i, j)
End If
Next j
End If
Next i
With Sheets("需要达到的效果")
.[a1].CurrentRegion = Empty
.[a1].Resize(UBound(cr), UBound(cr, 2)) = cr
End With
MsgBox "ok!"
End Sub
|
|