博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
20170716xlVba销售明细转销售单据
阅读量:5147 次
发布时间:2019-06-13

本文共 3190 字,大约阅读时间需要 10 分钟。

Sub CreateSaleList()    AppSettings    On Error GoTo ErrHandler    Dim StartTime As Variant    '开始时间    Dim UsedTime As Variant    '使用时间    StartTime = VBA.Timer    '记录开始时间    Dim Wb As Workbook    Dim Sht As Worksheet    Dim oSht As Worksheet    Dim NewSht As Worksheet    Dim iRow As Long    Dim NewRow As Long    Dim Dic As Object    Dim Key As String    Dim PageNo As Long    Set Wb = Application.ThisWorkbook    For Each oSht In Wb.Worksheets        If oSht.Name <> "明细" And oSht.Name <> "模板" Then            Debug.Print oSht.Name            oSht.Delete        End If    Next oSht    Set Sht = Wb.Worksheets("明细")    Set oSht = Wb.Worksheets("模板")    Set Dic = CreateObject("Scripting.Dictionary")    With Sht        iRow = 3        Do While .Cells(iRow, 1).Value <> ""            Key = .Cells(iRow, 1).Value            Dic(Key) = Dic(Key) + 1            PageNo = Int((Dic(Key) - 1) / 5) + 1            NewName = Key & "(" & PageNo & ")"            If Dic(Key) Mod 5 = 1 Then                '  On Error Resume Next                '  Wb.Worksheets(NewName).Delete                '  On Error GoTo 0                oSht.Copy After:=Wb.Worksheets(Wb.Worksheets.Count)                Set NewSht = Wb.Worksheets(Wb.Worksheets.Count)                NewSht.Name = Key & "(" & PageNo & ")"                NewSht.Range("B3").Value = .Cells(iRow, "C").Value                NewSht.Range("E3").Value = .Cells(iRow, "B").Value                NewSht.Range("G2").Value = NewSht.Range("G2").Value & .Cells(iRow, "A").Value                NewSht.Range("G3").Value = NewSht.Range("G3").Value & .Cells(iRow, "L").Value            End If            NewRow = 4 + (Dic(Key) - 1) Mod 5 + 1            NewSht.Cells(NewRow, 1).Value = .Cells(iRow, 6).Value            NewSht.Cells(NewRow, 2).Value = .Cells(iRow, 7).Value            NewSht.Cells(NewRow, 3).Value = .Cells(iRow, 8).Value            NewSht.Cells(NewRow, 4).Value = .Cells(iRow, 11).Value            NewSht.Cells(NewRow, 5).Value = .Cells(iRow, 10).Value            NewSht.Cells(NewRow, 6).Value = .Cells(iRow, 13).Value            NewSht.Cells(NewRow, 7).Value = .Cells(iRow, 9).Value            iRow = iRow + 1            If iRow = 60 Then Exit Do  '防止死循环        Loop    End With    Set Wb = Nothing    Set Sht = Nothing    Set oSht = Nothing    Set NewSht = Nothing    AppSettings False    UsedTime = VBA.Timer - StartTime    MsgBox "本次运行耗时:" & Format(UsedTime, "#0.0000秒")ErrorExit:    AppSettings False    Exit SubErrHandler:    If Err.Number <> 0 Then        MsgBox Err.Description & "!", vbCritical, "QQ 84857038"        Debug.Print Err.Description        Err.Clear        Resume ErrorExit    End IfEnd SubPublic Sub AppSettings(Optional IsStart As Boolean = True)    If IsStart Then        Application.ScreenUpdating = False        Application.DisplayAlerts = False        Application.Calculation = xlCalculationManual        Application.StatusBar = ">>>>>>>>Macro Is Running>>>>>>>>"    Else        Application.ScreenUpdating = True        Application.DisplayAlerts = True        Application.Calculation = xlCalculationAutomatic        Application.StatusBar = False    End IfEnd Sub

  

转载于:https://www.cnblogs.com/nextseven/p/7191888.html

你可能感兴趣的文章
NSString类-字符串
查看>>
MySql 游标笔记
查看>>
vim 穿越时空
查看>>
如何管理Entity Framework中得事务
查看>>
solrcloud线上创建collection,修改默认配置
查看>>
制作ubuntu16.04 自动安装iso镜像
查看>>
数据清洗
查看>>
我是如何自学Android,资料分享(2015 版)
查看>>
[Application]Ctrl+C终止程序代码
查看>>
for循环小例题
查看>>
C++ Win32 遍历窗口
查看>>
8,16小感
查看>>
《荣枯鉴》交结卷四
查看>>
PLSQL 11 注册码
查看>>
(六)配置克隆的服务器
查看>>
mybatis SQL 增删改查代码实现
查看>>
单片机(4)
查看>>
01dayC语言简介与初学C语言代码
查看>>
剑指offer ——重建二叉树
查看>>
委托+内置委托方法+多播委托+lambda表达式+事件
查看>>