|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 生成工作表()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object, dic As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
Set dic = CreateObject("scripting.dictionary")
Dim br()
For Each sh In Sheets
If sh.Index > 3 Then
dc(sh.Name) = ""
End If
Next sh
Set sht = Sheets("sheet1")
With Sheets("sheet1")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(1, Columns.Count).End(xlToLeft).Column
If r < 2 Then MsgBox "数据源为空!": End
ar = .Range("a4:h" & r)
End With
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
d(Trim(ar(i, 1))) = ""
End If
Next i
For Each k In d.keys
n = 0
ReDim br(1 To UBound(ar), 1 To 5)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) = k Then
If ar(i, 6) > 0 Then
n = n + 1
For j = 2 To 6
br(n, j - 1) = ar(i, j)
Next j
End If
End If
Next i
If Not dc.exists(k) Then
Sheets("模版").Copy after:=Sheets(Sheets.Count)
With ActiveSheet
.Name = k
.[c3].Resize(n, UBound(br, 2)) = br
End With
Else
dic.RemoveAll
With Sheets(k)
rs = .Cells(Rows.Count, 4).End(xlUp).Row
cr = .Range("a1:g" & rs)
For i = 2 To UBound(cr)
If Trim(cr(i, 4)) <> "" Then
dic(Trim(cr(i, 4))) = i
End If
Next i
m = r
For i = 1 To n
If Trim(br(i, 2)) <> "" Then
xh = dic(Trim(br(i, 2)))
If xh <> "" Then
yy = .Cells(xh, Columns.Count).End(xlToLeft).Column + 1
.Cells(xh, yy) = br(i, 5)
Else
m = m + 1
For j = 1 To 5
.Cells(m, j + 2) = br(i, j)
Next j
End If
End If
Next i
End With
End If
Next k
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
评分
-
1
查看全部评分
-
|