zoukankan      html  css  js  c++  java
  • 20170906xlVBA_CopyDataAndFormatFromSheets

    Public Sub GatherDataInSameWorkbook()
        AppSettings
        
        ' On Error GoTo ErrHandler
        
        Dim StartTime, UsedTime As Variant
        StartTime = VBA.Timer
        '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        Dim wb As Workbook
        Dim Sht As Worksheet
        Dim Rng As Range
        Dim OneSht As Worksheet
        Dim SheetCount As Long
        Const SHEET_NAME As String = "总表"
        Const HEAD_ROW As Long = 1
        
        '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        Set wb = Application.ThisWorkbook    '工作簿级别
        Set Sht = wb.Worksheets(SHEET_NAME)
        Sht.UsedRange.Offset(2).Clear
        
        For Each OneSht In wb.Worksheets
            If OneSht.Name Like "*系统" Then
                With OneSht
                    EndRow = .Cells.Find("*", .Cells(1, 1), xlValues, xlWhole, xlByRows, xlPrevious).Row
                    Set Rng = .Range("A3:Q" & EndRow)
                    Debug.Print .Name; "  "; Rng.Address
                    EndRow = Sht.Cells.Find("*", Sht.Cells(1, 1), xlValues, xlWhole, xlByRows, xlPrevious).Row + 1
                    Rng.Copy Sht.Cells(EndRow, 1)
                End With
            End If
        Next
        
        '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        UsedTime = VBA.Timer - StartTime
        Debug.Print "UsedTime :" & Format(UsedTime, "#0.0000 Seconds")
        'MsgBox "UsedTime :" & Format(UsedTime, "#0.0000 Seconds")
        
        
    ErrorExit:
        Set wb = Nothing
        Set Sht = Nothing
        Set OneSht = Nothing
        Set Rng = Nothing
        AppSettings False
        Exit Sub
        '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    ErrHandler:
        If Err.Number <> 0 Then
            MsgBox Err.Description & "!", vbCritical, " QQ "
            'Debug.Print Err.Description
            Err.Clear
            Resume ErrorExit
        End If
    End Sub
    Public Sub AppSettings(Optional IsStart As Boolean = True)
        Application.ScreenUpdating = IIf(IsStart, False, True)
        Application.DisplayAlerts = IIf(IsStart, False, True)
        Application.Calculation = IIf(IsStart, xlCalculationManual, xlCalculationAutomatic)
        Application.StatusBar = IIf(IsStart, ">>>>>>>>Macro Is Running>>>>>>>>", False)
    End Sub
    

      

  • 相关阅读:
    分析一个文本文件(英文文章)中各个词出现的频率,并且把频率最高的10个词打印出来
    求一个数组中的最大整数
    一个统计文本文件中各个英文单词出现频率的问题,并且输出频率最高的10个词
    Python学习一:基础语法
    Spring学习之二
    Spring学习之装配Bean
    Spring学习一
    缓存之ehcache
    解决axios传递参数后台无法接收问题
    服务端解决跨域问题
  • 原文地址:https://www.cnblogs.com/nextseven/p/7486820.html
Copyright © 2011-2022 走看看