|
1、用隐藏的话用end属性的确会出问题。
2、要源表格式一起过去的话,在分类里面把mrng定义为整行。拷贝后再把多余的列删掉。- Sub 分类()
- Dim mrng As Range, nsht As Worksheet
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Call sc '删除主表外的其它表
- Set d = CreateObject("scripting.dictionary")
- With Sheets(1)
- a = .[a65536].End(3).Row
- arr = .Range("a6:k" & a)
- For i = 1 To UBound(arr)
- d(arr(i, 11)) = ""
- Next
- brr = d.keys '第11列(K)列去重,存入brr数组
- For i = 0 To UBound(brr)
- xh = Mid(brr(i), 8, 1)
- xh = "第" & xh & "箱" 'xh=新建工作名
- ' Set mrng = .[a1:j5] '表头
- Set mrng = .Rows("1:5")
- For j = 1 To UBound(arr)
- If arr(j, 11) = brr(i) Then
- ' Set mrng = Union(mrng, .Cells(j + 5, 1).Resize(1, 10)) '合并相同箱号区域
- Set mrng = Union(mrng, .Rows(j + 5))
- End If
- Next
- Sheets.Add after:=Sheets(Sheets.Count)
- Set nsht = ActiveSheet
- nsht.Name = xh
- mrng.Copy nsht.[a1]
- nsht.Columns("K:X").Delete
- r = nsht.[a65536].End(3).Row
- For k = 6 To r '重编序号
- nsht.Cells(k, 1) = k - 5
- Next
- .Range("o1:x2").Copy nsht.Cells(r + 1, 1) '表尾
- nsht.Cells(r + 1, 3).Formula = "=SUM(c6:c" & r & ")"
- nsht.Cells(r + 1, 7).Formula = "=SUM(g6:g" & r & ")"
- Next
- .Activate
- End With
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|