提示:其他語言是Google翻譯的。 你可以訪問 English 版本。
登入
x
or
x
x
註冊
x

or

如何根據Excel中的列將數據拆分為多個工作表?

假設你有一個包含大量數據的工作表,現在,你需要根據數據拆分成多個工作表 名稱 列(請參見以下屏幕快照),並且名稱是隨機輸入的。 也許你可以先對它們進行排序,然後將它們逐個複制並粘貼到其他新的工作表中。 但這需要你耐心的重複複製和粘貼。 今天,我會談談一些快速的技巧來解決這個任務。

doc按列1分割數據

使用VBA代碼將數據分割成多個基於列的工作表

使用Kutools for Excel將數據分割成多個基於列的工作表


根據工作表中的特定列或行數將數據拆分為多個工作表:

如果您想根據特定列數據或行數將大工作表分成多個工作表, Kutools for Excel's 拆分數據 功能可以幫助您快速輕鬆地解決此任務。

doc按列6分割數據

Kutools for Excel:比200方便的Excel加載項,可以在60天免費試用。 下載並免費試用現在!


使用VBA代碼將數據分割成多個基於列的工作表


如果您想快速自動地根據列值拆分數據,以下VBA代碼是一個不錯的選擇。 請這樣做:

1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊,並將以下代碼粘貼到模塊窗口中。

Sub Splitdatabycol()
Dim lr As Long
Dim ws As Worksheet
Dim vcol, i As Integer
Dim icol As Long
Dim myarr As Variant
Dim title As String
Dim titlerow As Integer
Dim xTRg As Range
Dim xVRg As Range
Dim xWSTRg As Worksheet
On Error Resume Next
Set xTRg = Application.InputBox("Please select the header rows:", "Kutools for Excel", "", Type:=8)
If TypeName(xTRg) = "Nothing" Then Exit Sub
Set xVRg = Application.InputBox("Please select the column you want to split data based on:", "Kutools for Excel", "", Type:=8)
If TypeName(xVRg) = "Nothing" Then Exit Sub
vcol = xVRg.Column
Set ws = xTRg.Worksheet
lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
title = xTRg.AddressLocal
titlerow = xTRg.Cells(1).Row
icol = ws.Columns.Count
ws.Cells(1, icol) = "Unique"
Application.DisplayAlerts = False
If Not Evaluate("=ISREF('xTRgWs_Sheet!A1')") Then
Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = "xTRgWs_Sheet"
Else
Sheets("xTRgWs_Sheet").Delete
Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = "xTRgWs_Sheet"
End If
Set xWSTRg = Sheets("xTRgWs_Sheet")
xTRg.Copy
xWSTRg.Paste Destination:=xWSTRg.Range("A1")
ws.Activate
For i = (titlerow + xTRg.Rows.Count) To lr
On Error Resume Next
If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then
ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol)
End If
Next
myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants))
ws.Columns(icol).Clear
For i = 2 To UBound(myarr)
ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = myarr(i) & ""
Else
Sheets(myarr(i) & "").Move after:=Worksheets(Worksheets.Count)
End If
xWSTRg.Range(title).Copy
Sheets(myarr(i) & "").Paste Destination:=Sheets(myarr(i) & "").Range("A1")
ws.Range("A" & (titlerow + xTRg.Rows.Count) & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A" & (titlerow + xTRg.Rows.Count))
Sheets(myarr(i) & "").Columns.AutoFit
Next
xWSTRg.Delete
ws.AutoFilterMode = False
ws.Activate
Application.DisplayAlerts = True
End Sub

3。 然後按 F5 鍵運行代碼,彈出提示框提醒您選擇標題行,見截圖:

doc按列7分割數據

4。 然後點擊 OK 按鈕,在第二個提示框中,請選擇要拆分的列數據,請參見屏幕截圖:

doc按列8分割數據

5。 然後,點擊 OK,並且活動工作表中的所有數據都按列值拆分為多個工作表。 拆分工作表以拆分單元名稱命名。 看截圖:

doc按列2分割數據

備註:拆分工作表放置在主工作表所在工作簿的末尾。


使用Kutools for Excel將數據分割成多個基於列的工作表

作為一名Excel初學者,這個長的VBA代碼對我們來說有些困難,而且我們大多數人甚至不知道如何根據需要修改代碼。

在這裡,我會介紹一個多功能工具 - Kutools for Excel,其 拆分數據 實用程序不僅可以幫助您根據列將數據拆分為多個工作表,還可以按行數拆分數據。

Kutools for Excel : 與超過300方便的Excel加載項,在60天免費試用沒有限制.

如果你已經安裝 Kutools for Excel請按照以下步驟進行:

1。 選擇要分割的數據范圍。

2。 點擊 Kutools Plus > 工作表 > 拆分數據,看截圖:

doc按列3分割數據

3。 在 將數據拆分為多個工作表 對話框中,您需要:

1)。 選擇 專欄 在選項 基於分割 部分,然後從下拉列表中選擇要分割數據的列值。 (如果您的數據包含標題,並且您希望將它們插入到每個新的拆分工作表中,請檢查 我的數據有標題 選項。)

2)。 然後,您可以指定拆分工作表名稱 新的工作表名稱 部分,從中指定工作表名稱規則 規則 下拉列表中,您可以添加 字首 or 後綴 也是表格名稱。

3)。 點擊 OK 按鈕。 看截圖:

doc按列4分割數據

4。 現在,數據在新的工作簿中被分成多個工作表。

doc按列5分割數據

點擊下載Kutools for Excel和免費試用版吧!


使用Kutools for Excel將數據分割成多個基於列的工作表

Kutools for Excel 包含了比300更方便的Excel工具。 免費試用30天無限制。 立即下載免費試用!


相關文章:

如何按行數將數據拆分為多個工作表?


Kutools for Excel解決了您的大多數問題,並使您的生產率提高了80%

  • 重用: 快速插入 複雜的公式,圖表 以及你以前用過的任何東西; 加密單元格 密碼; 創建郵件列表 並發送電子郵件...
  • 超級方程式酒吧 (輕鬆編輯多行文字和公式); 閱讀佈局 (輕鬆讀取和編輯大量單元格); 粘貼到過濾範圍...
  • 合併單元格/行/列 不丟失數據; 分裂細胞含量; 組合重複的行/列...防止重複的細胞; 比較範圍...
  • 選擇複製或唯一 行; 選擇空行 (所有細胞都是空的); 超級查找和模糊查找 在許多工作簿中; 隨機選擇......
  • 精確複製 多個單元格而不更改公式參考; 自動創建參考 多張表; 插入項目符號,複選框等等......
  • 提取文本,添加文本,按位置刪除, 刪除空間; 創建和打印分頁小計; 在單元格內容和註釋之間轉換...
  • 超級過濾器 (將過濾方案保存並應用到其他工作表); 高級排序 按月/週/日,頻率等; 特殊過濾器 用粗體,斜體......
  • 結合工作簿和工作表; 根據鍵列合併表; 將數據拆分為多個表格; 批量轉換xls,xlsx和PDF...
  • 超過300強大的功能。 支持Office / Excel 2007-2019和365。 支持所有語言。 在您的企業或組織中輕鬆部署。 全功能30天免費試用。
kte tab 201905

Office選項卡為Office提供選項卡式界面,使您的工作更輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,Publisher,Access,Visio和Project。
  • 在同一窗口的新選項卡中打開並創建多個文檔,而不是在新窗口中。
  • 通過50%提高您的工作效率,每天為您減少數百次鼠標點擊!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Belinda Martinez · 5 years ago
    Works like a charm! Thank you.
  • To post as a guest, your comment is unpublished.
    Vickey · 6 years ago
    The VBA code worked perfectly. It does not seem to update the sheets as changes are made to Sheet1. Please assist.
    • To post as a guest, your comment is unpublished.
      Pieter · 5 years ago
      Hi,
      Thanks for the code it works for me!

      I only have two questions/remarks.

      1 the copied data does not inlclude the layout of the original file. Would it be possible to copy the data as table with autofilter?

      2 the copied data does not seem to be bounded to the title range.
      Is it possbible to adjust the code for a specific range or tablename?

      These adjustment would be very helpfull.

      Regards,

      Pieter
  • To post as a guest, your comment is unpublished.
    Niki · 6 years ago
    The VBA process worked perfectly, thank you so much for sharing your expertise and saving me a lot of time!
  • To post as a guest, your comment is unpublished.
    Cindy · 6 years ago
    I get an error when pressing F5 - GoTo Box asking for a reference??
  • To post as a guest, your comment is unpublished.
    Jagadesh.K · 6 years ago
    Split data into multiple worksheets based on column with VBA code shows some error. please try to rectify it & update the same. If you provide the sample excel files it will be really helpful.
    • To post as a guest, your comment is unpublished.
      Lok · 2 years ago
      Hallo,
      Thank you very much for the code.
      i am getting following error:

      Runtime error '6'
      overflow

      at the line
      For i = 2 To Ir

      Any solution for this.

      Thank you
    • To post as a guest, your comment is unpublished.
      Lok · 2 years ago
      I am getting following error:

      Runtime error '6'
      overflow

      After debugging show the line
      For i = 2 To Ir

      My excel rows are over 500,000.

      Is there any solution

      Thank you very much for the code.

      Best Regard
      Lok
    • To post as a guest, your comment is unpublished.
      Sarah · 2 years ago
      Hi,
      I've got 30000 cells in my worksheet and need to split them up in months. is there a code I can use to do it quicker. I have got 8 columns and date is column B.

      I've been playing around with the above code that is given but failing it big time.

      Could you please help me with this.

      Thanks in advance
    • To post as a guest, your comment is unpublished.
      Heidi · 2 years ago
      That was incredible! This process would have taken me over an hour to do, but it was done within 30 seconds. This one I will keep for my VBA library. Thank you!
    • To post as a guest, your comment is unpublished.
      Georges · 3 years ago
      Hi,
      thanks for the code it works for me!

      I am trying to find a code that split one master sheet into multiple sheet based on date