|
楼主 |
发表于 2014-7-15 18:03
|
显示全部楼层
本帖最后由 佛山小老鼠 于 2014-7-15 18:04 编辑
aoe1981 发表于 2014-7-15 09:20
531的按列拆分成工作表或工作簿代码值得好好钻研,不知道曹老师能不能帖一下代码……
- Option Explicit
- Sub 按列拆分成独立的工作簿()
- Dim f, St$, dic, arr1, d&, x&, arr2, y&, sh As Worksheet, ShName$, z&, Wb As Workbook
- Dim MySh As Worksheet
- f = Application.FileDialog(msoFileDialogFolderPicker).Show
- If f = 0 Then Exit Sub
- St = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
- Set dic = CreateObject("Scripting.Dictionary")
- ShName = ActiveSheet.Name
- Application.DisplayAlerts = False
- For Each sh In Sheets
- If sh.Name <> ShName Then
- sh.Delete
- End If
- Next sh
- On Error GoTo 100
- d = Application.InputBox("请选择众多要拆分的列", "选择", Type:=8).Column
- arr1 = Range("A1").CurrentRegion
- For x = 2 To UBound(arr1, 1)
- dic(arr1(x, d)) = ""
- Next x
- arr2 = dic.keys
- For y = 0 To UBound(arr2)
- Sheets.Add(after:=Sheets(Sheets.Count)).Name = arr2(y)
- Sheets(ShName).Select
- Range("A1").CurrentRegion.AutoFilter d, "=" & arr2(y)
- Range("A1").CurrentRegion.Copy Sheets(y + 2).Range("A1")
- Sheets(y + 2).Cells.EntireColumn.AutoFit
- Next y
- Range("A1").CurrentRegion.AutoFilter
- For z = 2 To Sheets.Count
- Sheets(z).Copy
- Set Wb = ActiveWorkbook
- With Wb
- .SaveAs Filename:=St & "" & Sheets(1).Name & ".xlsx"
- .Close
- End With
- Next z
- For Each MySh In Sheets
- If MySh.Name <> ShName Then
- MySh.Delete
- End If
- Next MySh
- Application.DisplayAlerts = True
- 100:
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|