|
楼主 |
发表于 2018-7-13 14:13
|
显示全部楼层
'=======================================================================
'03 递归后调用 统计
'=======================================================================
Sub jsjs汇总统计()
Application.ScreenUpdating = False
Dim i, i3, i6 As Long
ReDim brr(1 To 10, 1 To 23)
Dim SourceBook As Workbook
Dim SourceSheet As Worksheet
Dim ws As Worksheet
'将对象引用赋给变量或属性。
Set ws = Worksheets("统计汇总")
'Set ws2 = Worksheets("汇总")
'清空结果表
'ThisWorkbook.Sheets("结果表").Range("a2:ci" & Sheets("结果表").UsedRange.Rows.Count).Clear
'给变量赋值
i6 = 3
k = 1
' i2 = 2
'判断是否导入文件
If Len(Trim(ws.Cells(3, 25))) = 0 Then
MsgBox ("请导入目标所在的文件夹!")
Exit Sub
End If
Do
If Len(Trim(ws.Cells(i6, 25))) = 0 Then Exit Do
'Dim SourceBook As Workbook 打开导入的文件夹根路径下的文件
Set SourceBook = Workbooks.Open(Trim(ws.Cells(i6, 25)), False) 'Open 打开一个工作簿
'Dim SourceSheet As Worksheet 遍历打开的文件夹下的文件
For Each SourceSheet In SourceBook.Worksheets
'**************************************************************
'If SourceSheet.Name <> "汇总" And SourceSheet.[B3] <> "" Then Else On Error GoTo ERROR1
If Left(SourceSheet.Name, 2) <> "汇总" Then Else On Error GoTo ERROR1
'**************************************************************
'If Len(SourceSheet.[b8]) <> 0 Then i3 = True Else On Error GoTo ERROR1
i3 = True
'激活文件夹
'SourceSheet.Activate
Do While i3
'返回 Long,其中包含字符串内字符的数目,或是存储一变量所需的字节数。
'窗口表的品名项 看是不是为空
'If Len(Trim(SourceSheet.Cells(i3, 1))) = 0 Then Exit Do
'r = SourceSheet.Cells(Rows.Count, 1).End(xlUp).Row
'If SourceSheet.[B3] <> "" Then
brr(k, 1) = SourceSheet.[B3] '模具号4
'arr = SourceSheet.Range("a6:e" & r)
arr = SourceSheet.Range("a6:e" & 16)
For i = 1 To UBound(arr)
If arr(i, 1) <> "" Then
'n = n + 1
'k = 3
For n = 1 To 11
If n = 1 Then
brr(k, 2) = arr(n, 4) '件号6
brr(k, 3) = arr(n, 5) '件号6
End If
If n = 2 Then
brr(k, 4) = arr(n, 4) '件号6
brr(k, 5) = arr(n, 5) '件号6
End If
If n = 3 Then
brr(k, 6) = arr(n, 4) '件号6
brr(k, 7) = arr(n, 5) '件号6
End If
If n = 4 Then
brr(k, 8) = arr(n, 4) '件号6
brr(k, 9) = arr(n, 5) '件号6
End If
If n = 5 Then
brr(k, 10) = arr(n, 4) '件号6
brr(k, 11) = arr(n, 5) '件号6
End If
If n = 6 Then
brr(k, 12) = arr(n, 4) '件号6
brr(k, 13) = arr(n, 5) '件号6
End If
If n = 7 Then
brr(k, 14) = arr(n, 4) '件号6
brr(k, 15) = arr(n, 5) '件号6
End If
If n = 8 Then
brr(k, 16) = arr(n, 4) '件号6
brr(k, 17) = arr(n, 5) '件号6
End If
If n = 9 Then
brr(k, 18) = arr(n, 4) '件号6
brr(k, 19) = arr(n, 5) '件号6
End If
If n = 10 Then
brr(k, 20) = arr(n, 4) '件号6
brr(k, 21) = arr(n, 5) '件号6
End If
If n = 11 Then
brr(k, 22) = arr(n, 4) '件号6
brr(k, 23) = arr(n, 5) '件号6
End If
'错误模板
' If n = 11 And Len(SourceSheet.[a16]) = "扬州" Then
' brr(k, 22) = arr(n, 4) '件号6
' brr(k, 23) = arr(n, 5) '件号6
' End If
Next n
End If
Next i
i3 = False
' End If
Loop
Next
SourceBook.Close False
Set SourceSheet = Nothing
i6 = i6 + 1
k = k + 1
Loop
Sheet1.[B3].Resize(k, 23) = brr '将数据表数据放入brr数组,在将brr数组赋值给查询表
j = 1
MsgBox ("汇总完成")
ERROR1:
' MsgBox "表格不能为空"
Application.ScreenUpdating = True
End Sub
为什么我这句判断是否是汇总表没有用呢? |
|