|
楼主 |
发表于 2010-3-27 09:41
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
wj2368老师,以下是我在其他地方搜集到的分表代码,但是无奈不会编程,无法参透,请老师过目,是否有值得借鉴的地方?
Sub 按照总表A列数据分类存到各新表()
Dim irow, irow1, i, j As Integer
Dim H As New Collection
Dim sht As Worksheet
Dim A
'Worksheets("总表").Select
'Selection.QueryTable.Refresh BackgroundQuery:=False
Set A = ActiveCell
Application.ScreenUpdating = False
Application.DisplayAlerts = False '禁用警告框
For Each sht In Sheets
If sht.Name <> "总表" Then sht.Delete
Next
Sheets("总表").Copy Before:=Sheets(1)
On Error Resume Next
With Sheets("总表 (2)")
irow = [a65536].End(xlUp).Row
For i = 4 To irow
.Cells(i, 1) = "'" & .Cells(i, 1)
Next
For i = 4 To irow
H.Add .Cells(i, 1), CStr(.Cells(i, 1))
Next
For i = 1 To H.Count
.Cells.AutoFilter field:=1, Criteria1:=H(i)
Sheets.Add(after:=Sheets(Sheets.Count)).Name = H(i)
.[a4].CurrentRegion.Copy Sheets(CStr(H(i))).[a4]
irow1 = [a4].CurrentRegion.Rows.Count
For t = 1 To [a4].CurrentRegion.Columns.Count
Cells(1, t).ColumnWidth = .Cells(1, t).ColumnWidth
Next t
For j = 2 To irow1
Cells(j, 1) = Right(Cells(j, 1), Len(Cells(j, 1)))
Next j
.Cells.AutoFilter
Next i
.Delete
End With
A.Parent.Activate
A.Activate
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub |
|