|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
zhangguochang 发表于 2014-2-24 22:59
不是这样的,我的分表和主表在最后一列是不一样的,分表最后一列的余额是要有公式计算的
放弃字典法,先排序再复制数据:- Sub 字典拆分()
- Dim sh As Worksheet, arr, brr&(), m&, s$, i&, k, t, lc&
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- With [a1].CurrentRegion
- .Offset(5).Resize(.Rows.Count - 6).Sort Key1:=Range("C6"), Order1:=xlAscending, Header:=xlNo
- End With
- arr = [a1].CurrentRegion
- lc = UBound(arr, 2)
- ReDim brr(1 To UBound(arr))
- For i = 6 To UBound(arr) - 1
- If arr(i, 3) <> arr(i - 1, 3) Then
- m = m + 1
- brr(m) = i
- End If
- Next
- brr(m + 1) = i
- For Each sh In Sheets
- If sh.Name <> "总表" Then sh.Delete
- Next
- Set sh = Sheets("总表")
- For i = 1 To m
- sh.Copy After:=Sheets(Sheets.Count)
- With ActiveSheet
- For Each shp In .Shapes
- shp.Delete
- Next
- .Name = arr(brr(i), 3)
- .UsedRange.Offset(5).Clear
- sh.Cells(brr(i), 1).Resize(brr(i + 1) - brr(i), lc).Copy .Cells(6, 1)
- End With
- Next
- sh.Activate
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|