中燃料場報表生成器--庫存報表
阿新 • • 發佈:2018-11-10
Option Explicit Sub CmdGroup3() ' 判斷當前資料表是否為進銷存的銷售明細表 If Range("A1") <> "庫存分佈" Then MsgBox "當前資料表不是 《庫存分佈》 或者已經被修改,請確認!" End '結束程式的執行 End If ' 新建一個數據表,位於Sheet1後面 If Sheets(Sheets.Count).Name = "料場庫存明細" Then MsgBox "料場庫存明細 資料表已經存在,刪除後可重新建立" End End If Sheets.Add After:=Sheets(1) ActiveWorkbook.ActiveSheet.Name = "料場庫存明細" '合併後居中單元格 Range("A1").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .Font.Size = 12 .Font.Name = "黑體" .Font.Bold = True End With Range("A3:A4").Merge Range("B3:B4").Merge Range("C3:C4").Merge Range("D3:D4").Merge Range("E3:E4").Merge Range("F3:F4").Merge Range("G3:G4").Merge Range("H3:J3").Merge Range("K3:K4").Merge Range("L3:L4").Merge Range("M3:M4").Merge Range("N3:N4").Merge Range("A3:N3").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .Font.Size = 10 .Font.Name = "宋體" .Font.Bold = True End With Range("A1") = "工程材料盤點表" '填寫表頭 Range("A3") = "序號" Range("B3") = "類別" Range("C3") = "存貨名稱" Range("D3") = "規格型號" Range("E3") = "入庫時間" Range("F3") = "存放地點" Range("G3") = "單位" Range("H3") = "實盤" Range("H4") = "數量" Range("I4") = "單價" Range("J4") = "價值" Range("K3") = "庫房名稱" Range("L3") = "物資編碼" Range("M3") = "備註" '設定表頭格式 Range("H3:J4").Interior.Color = 12611584 '根據單元格的內容自動調整單元格大小 Cells.EntireColumn.AutoFit Cells.EntireRow.AutoFit '檢視銷售明細表一共記錄了多少行 Dim mItemCount As Integer mItemCount = ActiveWorkbook.Sheets(1).UsedRange.Rows.Count '需要的資料為第9行~mItemCount-1行,複製到對應的表中 ActiveWorkbook.Sheets(1).Range(ActiveWorkbook.Sheets(1).Cells(9, 4), ActiveWorkbook.Sheets(1).Cells(mItemCount - 1, 4)).Copy (ActiveSheet.Range("D5")) '規格型號 ActiveWorkbook.Sheets(1).Range(ActiveWorkbook.Sheets(1).Cells(9, 3), ActiveWorkbook.Sheets(1).Cells(mItemCount - 1, 3)).Copy (ActiveSheet.Range("C5")) '存貨名稱 ActiveWorkbook.Sheets(1).Range(ActiveWorkbook.Sheets(1).Cells(9, 2), ActiveWorkbook.Sheets(1).Cells(mItemCount - 1, 2)).Copy (ActiveSheet.Range("L5")) '物資編碼 ActiveWorkbook.Sheets(1).Range(ActiveWorkbook.Sheets(1).Cells(9, 7), ActiveWorkbook.Sheets(1).Cells(mItemCount - 1, 7)).Copy (ActiveSheet.Range("G5")) '單位 ActiveWorkbook.Sheets(1).Range(ActiveWorkbook.Sheets(1).Cells(9, 13), ActiveWorkbook.Sheets(1).Cells(mItemCount - 1, 13)).Copy (ActiveSheet.Range("H5")) '數量 ActiveWorkbook.Sheets(1).Range(ActiveWorkbook.Sheets(1).Cells(9, 14), ActiveWorkbook.Sheets(1).Cells(mItemCount - 1, 14)).Copy (ActiveSheet.Range("J5")) '金額 '填寫序號 Dim i As Integer For i = 5 To mItemCount - 5 Step 1 Cells(i, 1) = i - 4 If ActiveWorkbook.Sheets(1).Cells(i + 4, 9) = 0 Then Cells(i, 11).Value = ThisWorkbook.Sheets("配置").Range("A1").Value + "甲代乙供倉庫" Else Cells(i, 11).Value = ThisWorkbook.Sheets("配置").Range("A1").Value + "甲供倉庫" End If Next i End Sub