首页 > 代码库 > 20170324xlVBA最简单分类计数
20170324xlVBA最简单分类计数
Sub NextSeven_CodeFrame() Application.ScreenUpdating = False Application.DisplayAlerts = False Application.Calculation = xlCalculationManual Application.StatusBar = ">>>>>>>>程序正在运行>>>>>>>>" ‘On Error GoTo ErrHandler Dim StartTime, UsedTime As Variant StartTime = VBA.Timer ‘>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim Dic As Object Set Dic = CreateObject("Scripting.Dictionary") Dim Wb As Workbook Dim Sht As Worksheet Dim oSht As Worksheet Dim Rng As Range Dim Arr As Variant Dim EndRow As Long Const HEAD_ROW As Long = 1 Const SHEET_NAME As String = "数据" Const START_COLUMN As String = "A" Const END_COLUMN As String = "Z" Const OTHER_HEAD_ROW As Long = 1 Const OTHER_SHEET_NAME As String = "重复" ‘>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Set Wb = Application.ThisWorkbook Set Sht = Wb.Worksheets(SHEET_NAME) With Sht EndRow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row Set Rng = .Range(.Cells(HEAD_ROW + 1, START_COLUMN), .Cells(EndRow, END_COLUMN)) Arr = Rng.Value For i = LBound(Arr) To UBound(Arr) Key = "‘" & CStr(Arr(i, 4)) If Key <> "‘" Then Dic(Key) = Dic(Key) + 1 End If Next i End With ‘>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> For Each onekey In Dic.KEYS If Dic(onekey) < 2 Then Dic.Remove onekey End If Next onekey ‘>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Set oSht = Wb.Worksheets(OTHER_SHEET_NAME) With oSht .Cells.ClearContents .Range("A1:B1").Value = http://www.mamicode.com/Array("ID", "次数") If Dic.Count > 0 Then .Range("A2").Resize(Dic.Count, 2).Value = http://www.mamicode.com/Application.WorksheetFunction.Transpose(Array(Dic.KEYS, Dic.ITEMS))"本次耗时:" & Format(UsedTime, "0.000秒"), vbOKOnly, "NextSeven Excel Studio" ErrorExit: Set Wb = Nothing Set Sht = Nothing Set Rng = Nothing Set oSht = Nothing Set Dic = Nothing Application.ScreenUpdating = True Application.DisplayAlerts = True Application.Calculation = xlCalculationAutomatic Application.StatusBar = False Exit Sub ‘>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ErrHandler: If Err.Number <> 0 Then MsgBox Err.Description & "!", vbCritical, "NextSeven Excel Studio" ‘Debug.Print Err.Description Err.Clear Resume ErrorExit End If End Sub
20170324xlVBA最简单分类计数
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。