首页 > 代码库 > 20170617xlVBA调查问卷基础数据分类计数
20170617xlVBA调查问卷基础数据分类计数
Public Sub GatherDataPicker() Application.ScreenUpdating = False Application.DisplayAlerts = False Application.Calculation = xlCalculationManual Application.StatusBar = ">>>>>>>>程序正在运行>>>>>>>>" Dim Dic As Object On Error GoTo ErrHandler Dim StartTime, UsedTime As Variant StartTime = VBA.Timer ‘>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim wb As Workbook Dim Sht As Worksheet Dim OpenWb As Workbook Dim OpenSht As Worksheet Const SHEET_INDEX = 1 Const OFFSET_ROW As Long = 1 Dim FolderPath As String Dim FileName As String Dim FileCount As Long Dim qIndex As String ‘>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> With Application.FileDialog(msoFileDialogFolderPicker) .InitialFileName = ThisWorkbook.Path .AllowMultiSelect = False .Title = "请选取Excel工作簿所在文件夹" If .Show = -1 Then FolderPath = .SelectedItems(1) Else MsgBox "您没有选中任何文件夹,本次汇总中断!" Exit Sub End If End With If Right(FolderPath, 1) <> "\" Then FolderPath = FolderPath & "\" ‘>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Set wb = Application.ThisWorkbook ‘工作簿级别 Set Sht = wb.ActiveSheet Sht.UsedRange.Offset(0, 2).ClearContents ‘FolderPath = ThisWorkbook.Path & "\" FileCount = 0 FileName = Dir(FolderPath & "*.xls*") Do While FileName <> "" If FileName <> ThisWorkbook.Name Then Set Dic = CreateObject("Scripting.Dictionary") FileCount = FileCount + 1 Set OpenWb = Application.Workbooks.Open(FolderPath & FileName) With OpenWb Set OpenSht = OpenWb.Worksheets(1) With OpenSht endrow = .Cells(.Cells.Rows.Count, 2).End(xlUp).Row Set Rng = .Range("a1").CurrentRegion arr = Rng.Value For j = LBound(arr, 2) + 1 To UBound(arr, 2) For i = LBound(arr) + 1 To UBound(arr) FileName = Split(FileName, ".")(0) qIndex = Replace(arr(1, j), "Q", "") Key = CStr(arr(i, j)) ‘Dim uk As String uk = FileName & ";" & qIndex & ";" & Key Dic(uk) = Dic(uk) + 1 ‘Debug.Print FileName, " "; qIndex Next i Next j End With .Close False End With With Sht endcol = .Cells(1, .Cells.Columns.Count).End(xlToLeft).Column + 1 endrow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row .Cells(1, endcol).Value = http://www.mamicode.com/FileName"" Then qIndex = .Cells(i, 1).Value Key = .Cells(i, 2).Value Debug.Print i; " "; qIndex If Key <> "无效" Then uk = FileName & ";" & qIndex & ";" & Key .Cells(i, endcol).Value = http://www.mamicode.com/Dic(uk)";" & qIndex & ";" For Each k In Dic.keys If InStr(1, k, uk) > 0 Then mysum = mysum + Dic(k) Next k .Cells(i, endcol).Value = http://www.mamicode.com/mysum"!", vbCritical, "NextSeven Excel Studio" ‘Debug.Print Err.Description Err.Clear Resume ErrorExit End If End Sub
20170617xlVBA调查问卷基础数据分类计数
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。