您好,登錄后才能下訂單哦!
這篇文章給大家介紹excle表格如何將數據拆分成不通的sheet頁,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
13先展示最后效果:
代碼如下
Sub CFGZB() Dim myRange As Variant Dim myArray Dim titleRange As Range Dim title As String Dim columnNum As Integer myRange = Application.InputBox(prompt:="請選擇標題行:", Type:=8) myArray = WorksheetFunction.Transpose(myRange) Set titleRange = Application.InputBox(prompt:="請選擇拆分的表頭,必須是第一行,且為一個單元格,如:“姓名”", Type:=8) title = titleRange.Value columnNum = titleRange.Column Application.ScreenUpdating = False Application.DisplayAlerts = False Dim i&, Myr&, Arr, num& Dim d, k For i = Sheets.Count To 1 Step -1 If Sheets(i).Name <> "Sheet1" Then Sheets(i).Delete End If Next i Set d = CreateObject("Scripting.Dictionary") Myr = Worksheets("Sheet1").UsedRange.Rows.Count Arr = Worksheets("Sheet1").Range(Cells(2, columnNum), Cells(Myr, columnNum)) For i = 1 To UBound(Arr) d(Arr(i, 1)) = "" Next k = d.keys For i = 0 To UBound(k) Set conn = CreateObject("adodb.connection") conn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName Sql = "select * from [Sheet1$] where " & title & " = '" & k(i) & "'" Worksheets.Add after:=Sheets(Sheets.Count) With ActiveSheet .Name = k(i) For num = 1 To UBound(myArray) .Cells(1, num) = myArray(num, 1) Next num .Range("A2").CopyFromRecordset conn.Execute(Sql) End With Sheets(1).Select Sheets(1).Cells.Select Selection.Copy Worksheets(Sheets.Count).Activate ActiveSheet.Cells.Select Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Application.CutCopyMode = False Next i conn.Close Set conn = Nothing Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
6.
7.
8.
9.
10
11.
12注意:
1)原始數據表要從第一行開始有數據,并且不能有合并單元格;
2)打開工作簿時需要開啟宏,否則將無法運行代碼。
2、生成目錄
a、新建一個sheet,名字改為”目錄” 在開發工具中
Sub createmenu()
For i = 1 To Sheets.Count
Cells(i, 1) = Sheets(i).Name
'Cells(i, 2) = Sheets(i).Cells(2, 2).Value
Next i
End Sub
雙擊下目錄那個sheet 粘貼并執行;
b、增加超鏈接
在sheet1中B2單元格中定義超鏈接函數,錄入=HYPERLINK("#"&A2&"!A1",A2)
c、增加返回目錄
選中所有sheet(目錄除外)在任意一張中選個空白的單元格輸入 =HYPERLINK(“#目錄!A1”,”返回目錄”)
關于excle表格如何將數據拆分成不通的sheet頁就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。