標題:
[發問]
1張主工作表篩選後新增工作表及命名
[打印本頁]
作者:
missbb
時間:
2018-6-8 23:24
標題:
1張主工作表篩選後新增工作表及命名
sub copyfile()
'將DATA工作表內按部門篩選後另存工作表
For i = 1 To 3
Cells(1, 1).AutoFilter 3, i
Cells(1, 1).CurrentRegion.Copy '這樣出錯, 只可將部份內容另存工作表
Worksheets.Add after:=Worksheets(Worksheets.Count)[attach]28806[/attach]
Worksheets(Worksheets.Count).Name = "SHEET" & i
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets(1).Select
ActiveSheet.ShowAllData
Next i
ActiveSheet.AutoFilterMode = False
End Sub
Sub myName() '用每工仍表的C6儲存格為工作表命名
For i = 2 To Worksheets.Count
Worksheets(i).Name = Worksheets(i).Cells(2, 1)
Next
End Sub
複製代碼
作者:
ikboy
時間:
2018-6-9 10:20
Sub zz()
Application.ScreenUpdating = 0
Dim rng As Range, d As Object, ws As Worksheet
Set ws = ActiveSheet
ws.AutoFilterMode = False
c = [a3].CurrentRegion.Columns.Count
Set d = CreateObject("scripting.dictionary")
Set rng = Range([a5], Cells(Cells(Rows.Count, 1).End(3).Row, c))
a = rng.Columns(3)
For i = 2 To UBound(a)
d(a(i, 1)) = ""
Next
k = d.keys
For i = 0 To UBound(k)
ws.Copy after:=Sheets(Sheets.Count)
ActiveSheet.AutoFilterMode = False
[a3].CurrentRegion.Clear
With ws
rng.AutoFilter Field:=3, Criteria1:=k(i)
.[a3].CurrentRegion.Copy [a3]
End With
ActiveSheet.Name = [c6].Value
Next
Application.ScreenUpdating = 1
End Sub
複製代碼
作者:
missbb
時間:
2018-6-11 17:20
回復
2#
ikboy
感謝, 我要洧化及學習.:D
作者:
missbb
時間:
2018-6-11 19:28
本帖最後由 missbb 於 2018-6-11 19:32 編輯
大大IKBOY你好, 我將你指導的放入較多資料的EXCEL, 自己加入檢視資料的改動. 但執行時出現1004的錯誤, 請幫忙看那裡出錯?
我是要在SHEET DATA之後, 保留工作表1及工作表二,即分部門新增的工作表, 是要在工作表二之後新增.
[attach]28814[/attach]
Sub sortingsavesheet2()
'use this , sorting dept then save individualsheet with deptname
Application.ScreenUpdating = 0
Dim rng As Range, d As Object, ws As Worksheet
Set ws = ActiveSheet
ws.AutoFilterMode = False
c = [a3].CurrentRegion.Columns.Count
Set d = CreateObject("scripting.dictionary")
Set rng = Range([a5], Cells(Cells(Rows.Count, 1).End(3).Row, c))
a = rng.Columns(3)
For i = 2 To UBound(a)
d(a(i, 1)) = ""
Next
k = d.keys
For i = 0 To UBound(k)
ws.Copy after:=Sheets(Sheets.Count)
ActiveSheet.AutoFilterMode = False
[a3].CurrentRegion.Clear
With ws
rng.AutoFilter Field:=3, Criteria1:=k(i)
.[a3].CurrentRegion.Copy [a3]
Range("F6").Select
With ActiveWindow
.SplitColumn = 5
.SplitRow = 5
End With
ActiveWindow.FreezePanes = True
End With
ActiveSheet.Name = [c6].Value
Next
Application.ScreenUpdating = 1
With Sheets("data").Activate
If ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
[color=Red]'自行加入凍結窗及最後返回DATA的F6[/color]
Range("F6").Select
With ActiveWindow
.SplitColumn = 5
.SplitRow = 5
End With
ActiveWindow.FreezePanes = True
End With
End Sub
複製代碼
回復
2#
ikboy
作者:
ikboy
時間:
2018-6-12 10:08
檔案無法打開
作者:
missbb
時間:
2018-6-12 20:57
[attach]28827[/attach]
補回附件:P
回復
5#
ikboy
作者:
ikboy
時間:
2018-6-14 14:18
代碼不要放入sheets內。
作者:
missbb
時間:
2018-6-15 08:52
感謝協力
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)