-
函数运行效果如下:
只要在E1单元格输入:表名
E2单元格输入数组公式:(公式输完按CTRL+SHIFT+ENTER结束公式)
=IFERROR(INDEX(B$1:B$9,SMALL(IF($A$1:$A$9=$E$1,ROW(A$1:A$9),""),ROW(A1))),"")
下拉公式到你需要的行
-
代码如下:
Sub classify()
Application.DisplayAlerts = False
Dim x, y, n, j
Dim ar, br, cr(1 To 10000, 1 To 2)
Dim sh As Worksheet
Dim d
Set d = CreateObject("scripting.dictionary")
For m = Sheets.Count() To 1 Step -1
If Worksheets(m).Name <> "Sheet1" Then
Worksheets(m).Delete
End If
Next m
ar = Sheet1.Range("a2:b" & Range("a65536").End(3).Row)
For x = 1 To UBound(ar)
d(ar(x, 1)) = ""
Next
br = d.keys
For n = 0 To UBound(br)
Set sh = Worksheets.Add(after:=Worksheets(Sheets.Count()))
sh.Name = br(n)
sh.Range("a1:b1") = Array("表名", "数据")
For y = 1 To UBound(ar)
If br(n) = ar(y, 1) Then
j = j + 1
cr(j, 1) = ar(y, 1)
cr(j, 2) = ar(y, 2)
End If
Next y
sh.Range("a2").Resize(j, 2) = cr
j = 0: Erase cr
Next n
Application.DisplayAlerts = True
End Sub
亲测有效
如本站内容“对您有用”,欢迎随意打赏,让我们持续更新!
打赏