|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 汇总() '
Dim sht As Worksheet
Dim brr1(), sn()
For si = 1 To Worksheets.Count '遍历工作表,将汇总表数量赋值给数组sn()
If Worksheets(si).Name Like "*汇总表*" Then
ReDim Preserve sn(si)
sn(si) = Split(Worksheets(si).Name, "汇总表")(0)
End If
Next
For Each sht In Worksheets '遍历工作表
If sht.Name Like "*汇总表*" Then
m = sht.Range("a65536").End(3).Row
sht.Range("A2:e" & m + 2).ClearContents '清空当前表数据"
Else
bm = sht.Name '工作表名称
m = sht.Cells(65536, "s").End(3).Row
ReDim brr1(1 To 5, 1 To m) '根据工作表使用区域采用转置法重新定义变量
If m < 3 Then m = 3
arr = sht.Range("s3:v" & m) '工作表汇总区域
arr2 = sht.Range("a3:a" & m) '工作表序号
For ii = 1 To UBound(sn) '根据汇总表数循环
For i = 1 To UBound(arr) '工作表循环
If arr(i, 1) = "是" And arr(i, 2) = sn(ii) Then '工作表循环条件
n1 = n1 + 1
For j = 2 To UBound(arr, 2)
brr1(j, n1) = arr(i, j)
Next j
brr1(1, n1) = arr2(i, 1)
brr1(5, n1) = bm
End If
Next i
r = Sheets(sn(ii) & "汇总表").Cells(Rows.Count, "A").End(xlUp).Row + 1
If n1 <> 0 Then
Sheets(sn(ii) & "汇总表").Range("A" & r).Resize(n1, 5) = Application.WorksheetFunction.Transpose(brr1) '将变量赋值给对应表
End If
n1 = 0 '重新定义
Next ii
End If
Next sht
End Sub
|
|