Sub list_sheets_name()
Dim i As Integer
Sheets.Add before:=Sheets(1)
For i = 2 To Sheets.Count
Sheets(1).Cells(i, 1) =Sheets(i).Name 'list all sheets name
Next
End Sub
Sub Collect_Cost_Sheets()
'
Dim s, i, j As Integer
Dim shtname, sku, plantline As String
j = 1
'将各SKU的Cost-sheets的Sheet名称列在P列,依次收集各Sheets的Cost-sheets
For s = 1 ToApplication.CountA(Sheets("CostSheetsSum").Columns("P:P"))
shtname = Sheets("CostSheetsSum").Range("P" &s) '记下Sheet名称
Sheets(shtname).Select
n = Application.CountA(Sheets(shtname).Rows("2:2")) '统计第2行生产线代码个数
For i = 1 To n '依次收集各生产线的Cost-sheets
Sheets(shtname).Select
sku = Sheets(shtname).Range("D1").Value '记下SKUcode
plantline = Sheets(shtname).Cells(3, 4 + 4 * i) &Sheets(shtname).Cells(3, 5 + 4 * i) '记下生产线
Sheets(shtname).Range("B3:G35").Select '收集通用数据
Selection.Copy
Sheets("CostSheetsSum").Select
Sheets("CostSheetsSum").Cells(1 + (j - 1) * (35- 2), 4).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Sheets(shtname).Select '收集生产线个别数据
Sheets(shtname).Cells(3, 4 + 4 *i).Resize(33,4).Select
Selection.Copy
Sheets("CostSheetsSum").Select
Sheets("CostSheetsSum").Cells(1 + (j - 1) * (35- 2), 4 + 6).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Sheets("CostSheetsSum").Cells(1 + (j - 1) * (35- 2), 1).Resize(33, 1).Value = shtname
Sheets("CostSheetsSum").Cells(1 + (j - 1) * (35- 2), 2).Resize(33, 1).Value = sku
Sheets("CostSheetsSum").Cells(1 + (j - 1) * (35 -2), 3).Resize(33, 1).Value = plantline
j = j + 1
Next
Next
End Sub
|