|
Sub 拆分()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
Application.DisplayAlerts = False
For Each sht In Sheets
If sht.Index > 2 Then
sht.Delete
End If
Next sht
Application.DisplayAlerts = True
With Sheets("需求")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "需求表为空!": End
ar = .Range("a1:a" & r)
End With
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
d(ar(i, 1)) = ""
End If
Next i
With Sheets("BOM全表")
rs = .Cells(Rows.Count, 5).End(xlUp).Row
If rs < 2 Then MsgBox "BOM全表为空!": End
br = .Range("a1:o" & rs)
For i = 2 To UBound(br)
If br(i, 1) <> "" Then
If d.exists(br(i, 1)) Then
m = .Cells(i, 1).End(xlDown).Row
If m > rs Then
m = rs + 1
Else
m = m
End If
.Copy after:=Sheets(Sheets.Count)
Set sh = ActiveSheet
sh.Name = br(i, 1)
sh.Range("a2:o" & rs) = Empty
.Range(.Cells(i, 1), .Cells(m - 1, 15)).Copy sh.[a2]
End If
End If
Next i
End With
Application.ScreenUpdating = True
MsgBox "拆分完毕!"
End Sub
|
评分
-
1
查看全部评分
-
|