|
楼主 |
发表于 2018-7-26 10:21
|
显示全部楼层
Sub 分表()
Dim sht As Worksheet, Bt1 As Range, Bt2 As Range, Bt3 As Range
Dim toprow&, i&, lastrow&, BOM$
Set dic = CreateObject("scripting.dictionary")
Application.ScreenUpdating = False
For Each sht In Worksheets
If sht.Name <> "基表" Then
Application.DisplayAlerts = False
sht.Delete
Application.DisplayAlerts = True
End If
Next
With Worksheets("基表")
toprow = .Cells(.Rows.Count, 1).End(3).Row
For i = 3 To toprow
Set Bt1 = Union(.[a1].Resize(2, 2), .Cells(i, 1).Resize(1, 2))
Set Bt2 = Union(.[c1].Resize(2, 13), .Cells(i, 31).Resize(1, 13))
Set Bt3 = Union(.[p1].Resize(2, 21), .Cells(i, 16).Resize(1, 21))
BOM = Trim(.Cells(i, 3).Value)
If Not dic.exists(BOM) Then
dic(BOM) = BOM
Sheets.Add after:=Worksheets(Sheets.Count)
With ActiveSheet
Bt1.Copy .[a1]
Bt2.Copy .[a4]
Bt3.Copy .[a7]
.Cells.Font.Size = 9
.Columns.AutoFit
.Name = dic(BOM)
End With
Else
With Sheets(dic(BOM))
lastrow = .Cells(.Rows.Count, 1).End(3).Row + 1
Worksheets("基表").Cells(i, 16).Resize(1, 21).Copy .Cells(lastrow, 1)
End With
End If
Next i
.Select
End With
Application.ScreenUpdating = True
End Sub
|
-
运行到这一行时候报错了
|