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

从进销存系统导出的销售明细表 一键 生成 出库报表---V1.0版本

 

Sub CmdGroup1()
'
' CmdGroup1 宏
' 从进销存到处的销售明细表生成料场出库报表
'



' 判断当前数据表是否为进销存的销售明细表
    
    If Range("A1") <> "销售明细表" Then
        MsgBox "当前数据表不是 《销售明细表》 或者已经被修改,请确认!"
        End '结束程序的运行
    End If
    
    
' 新建一个数据表,位于Sheet1后面

    Sheets.Add After:=Sheets(1)
    ThisWorkbook.ActiveSheet.Name = "广宗料场出库明细"
    
    
    '合并后居中单元格
    Range("A1:N1").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
    End With
    Selection.Merge
    
    Range("A1") = "材料出库明细表"
    
    
    '填写表头
    Range("A2") = "序号"
    Range("B2") = "出库日期"
    Range("C2") = "纸质出库单编号"
    Range("D2") = "采购网出库单编号"
    Range("E2") = "物资编码"
    Range("F2") = "物资名称"
    Range("G2") = "单位"
    Range("H2") = "出库数量"
    Range("I2") = "含税单价"
    Range("J2") = "含税金额"
    Range("K2") = "其它费用"
    Range("L2") = "领料单位"
    Range("M2") = "库房名称"
    Range("N2") = "备注"
    
    '设置表头格式
    Rows("1:1").RowHeight = 22.5
    Range("A1:N1").Font.Size = 18
    Range("A2:N2").Font.Size = 14
    Range("A2:N2").Font.Bold = True
    
    With Range("A2:N2").Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 0.499984740745262
        .PatternTintAndShade = 0
    End With
    With Range("A2:N2").Font
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
    End With
    
    '根据单元格的内容自动调整单元格大小
    Cells.EntireColumn.AutoFit
    Cells.EntireRow.AutoFit
    
    '查看销售明细表一共记录了多少行
    Dim mItemCount As Integer
    mItemCount = Sheet1.UsedRange.Rows.Count
    
    '需要的数据为第10行~mItemCount-1行,复制到对应的表中
    Sheet1.Range(Sheet1.Cells(10, 2), Sheet1.Cells(mItemCount - 1, 2)).Copy (ActiveSheet.Range("C3"))   '单据编号
    Sheet1.Range(Sheet1.Cells(10, 3), Sheet1.Cells(mItemCount - 1, 3)).Copy (ActiveSheet.Range("B3"))   '单据日期
    Sheet1.Range(Sheet1.Cells(10, 8), Sheet1.Cells(mItemCount - 1, 8)).Copy (ActiveSheet.Range("E3"))   '物资编码
    Sheet1.Range(Sheet1.Cells(10, 9), Sheet1.Cells(mItemCount - 1, 9)).Copy (ActiveSheet.Range("F3"))   '名称
    Sheet1.Range(Sheet1.Cells(10, 16), Sheet1.Cells(mItemCount - 1, 16)).Copy (ActiveSheet.Range("G3")) '单位
    Sheet1.Range(Sheet1.Cells(10, 17), Sheet1.Cells(mItemCount - 1, 17)).Copy (ActiveSheet.Range("H3")) '数量
    Sheet1.Range(Sheet1.Cells(10, 19), Sheet1.Cells(mItemCount - 1, 19)).Copy (ActiveSheet.Range("I3")) '单价
    Sheet1.Range(Sheet1.Cells(10, 20), Sheet1.Cells(mItemCount - 1, 20)).Copy (ActiveSheet.Range("J3")) '金额
    Sheet1.Range(Sheet1.Cells(10, 5), Sheet1.Cells(mItemCount - 1, 5)).Copy (ActiveSheet.Range("L3"))   '来往单位
    Sheet1.Range(Sheet1.Cells(10, 7), Sheet1.Cells(mItemCount - 1, 7)).Copy (ActiveSheet.Range("M3"))   '库房名称
    
    
    '填写序号
    Dim i As Integer
    For i = 3 To mItemCount - 8 Step 1
        Cells(i, 1) = i - 2
    Next i
    
  
  
    
End Sub

 

你可能感兴趣的:(VBA)