|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
这样试试:- Sub kao()
- Dim d As Object, arr, ar, ghb, sh
- Dim i%
- Dim skey
- ghb = Array("一星会员", "二星会员", " 三星会员")
- For Each sh In Sheets
- If sh.Name <> "Sheet2" Then
- Application.DisplayAlerts = False
- sh.Delete
- Application.DisplayAlerts = True
- End If
- Next
- Set d = CreateObject("scripting.dictionary")
- ar = Sheet1.[a1].CurrentRegion
- For i = 2 To UBound(ar, 1)
- If d.exists(ar(i, 3)) = False Then Set d(ar(i, 3)) = CreateObject("Scripting.Dictionary")
- d(ar(i, 3))(ar(i, 2)) = d(ar(i, 3))(ar(i, 2)) & "," & ar(i, 1)
- Next
- For Each skey In d.keys
- Sheets.Add after:=Sheets(Sheets.Count)
- Sheets(Sheets.Count).Name = skey
- Sheets(Sheets.Count).[a1:c1] = ghb
- With ActiveSheet
- For i = 1 To 3
- arr = Split(Mid(d(skey)(ghb(i - 1)), 2), ",")
- If UBound(arr) > -1 Then [a2].Offset(0, i - 1).Resize(UBound(arr) + 1, 1) = Application.Transpose(arr)
- Next
- End With
- Next
- MsgBox "ok"
- End Sub
复制代码 |
|