中燃料场报表生成器--库存报表

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

 

你可能感兴趣的:(VBA)