Cynghorion Excel: Rhannu data yn daflenni gwaith / llyfrau gwaith lluosog yn seiliedig ar werth colofn
When managing large datasets in Excel, it can be highly beneficial to split data into multiple worksheets based on specific column values. This method improves not only the organization of data but also enhances readability and facilitates easier data analysis.
Suppose you have a large sales record containing multiple entries such as the product name, the quantity sold of the first quarter. The goal is to split this data into separate worksheets based on each product name so that individual sales performance can be analyzed separately.
Split data into multiple worksheets based on column value
Split data into multiple workbooks based on column value with VBA code
Split data into multiple worksheets based on column value
Normally, you can sort the data list first, and then copy and paste them one by one into other new worksheets. But this will need your patience to copy and paste repeatedly. In this section, we will introduce two straightforward methods to efficiently tackle this task in Excel, saving you time and reducing the potential for errors.
Split data into multiple worksheets based on column value with VBA code
1. Daliwch y ALT + F11 allweddi i agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.
2. Cliciwch Mewnosod > Modiwlau, a gludwch y cod canlynol yn y Ffenestr Modiwl.
Sub Splitdatabycol()
'updateby Extendoffice
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
Dim xWS 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
Set xWS = Sheets.Add(after:=Worksheets(Worksheets.Count))
xWS.Name = myarr(i) & ""
Else
xWS.Move after:=Worksheets(Worksheets.Count)
End If
xWSTRg.Range(title).Copy
xWS.Paste Destination:=xWS.Range("A1")
ws.Range("A" & (titlerow + xTRg.Rows.Count) & ":A" & lr).EntireRow.Copy xWS.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. Yna, pwyswch F5 key to run the code, and a prompt box is popped out to remind you select the header row, and then, click OK. Gweler y screenshot:
4. In the second prompt box, please select the column data that you want to split based on, then, click OK. Gweler y screenshot:
5. All data in the active worksheet is divided into multiple worksheets based on the column values. The resulting worksheets are named according to the values in the split cells and are placed at the end of the workbook. See screenshot:
Split data into multiple worksheets based on column value with Kutools for Excel
Kutools ar gyfer Excel brings smart feature – Data Hollti right into your Excel environment. Splitting data into multiple worksheets is no longer a challenge. Our intuitive tool automatically divides your dataset based on the chosen column value or rows count, ensuring that each piece of information is exactly where you need it. Say goodbye to the tedious task of manually organizing your spreadsheets and embrace a faster, error-free way to manage your data.
Ar ôl gosod Kutools ar gyfer Excel, dewiswch yr ystod ddata, ac yna cliciwch Kutools Byd Gwaith > Data Hollti i agor y Split Data into multiple worksheets blwch deialog.
- dewiswch Colofn benodol opsiwn yn y Hollti yn seiliedig ar section, and choose the column value which you want to split the data based on from the drop-down list.
- Os oes gan eich data benawdau a'ch bod am eu mewnosod ym mhob taflen waith hollt newydd, gwiriwch Mae penawdau yn fy data option. (You can specify the number of header rows based on your data. For example, if your data contains two headers, please type 2.)
- Yna gallwch chi nodi'r enwau taflen waith rhanedig, o dan y Enw taflenni gwaith newydd section, specify the worksheet names rule from the Rules drop down list, you can add the Rhagolwg or Ôl-ddodiad ar gyfer yr enwau dalen hefyd.
- Cliciwch ar y OK botwm. Gweler y screenshot:
Now, the data in the worksheet is split into multiple worksheets in a new workbook.
Split data into multiple workbooks based on column value with VBA code
Occasionally, rather than dividing data into multiple worksheets, it may be more beneficial to split the data into separate workbooks based on a key column. Here's a step-by-step guide on how to use VBA code to automate the process of splitting data into multiple workbooks based on a specific column value.
1. Daliwch y ALT + F11 allweddi i agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.
2. Cliciwch Mewnosod > Modiwlau, a gludwch y cod canlynol yn y Ffenestr Modiwl.
Sub SplitDataByColToWorkbooks()
' Updateby Extendoffice
Dim lr As Long
Dim ws As Worksheet
Dim vcol, i As Integer
Dim myarr As Variant
Dim title As String
Dim titlerow As Integer
Dim xTRg As Range
Dim xVRg As Range
Dim xWS As Workbook
Dim savePath As String
' Set the directory to save new workbooks
savePath = "C:\Users\AddinsVM001\Desktop\multiple files\" ' Modify this path as needed
Application.DisplayAlerts = False
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.Address(False, False)
titlerow = xTRg.Row
ws.Columns(vcol).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=ws.Cells(1, ws.Columns.Count), Unique:=True
myarr = Application.Transpose(ws.Cells(1, ws.Columns.Count).Resize(ws.Cells(ws.Rows.Count, ws.Columns.Count).End(xlUp).Row).Value)
ws.Cells(1, ws.Columns.Count).Resize(ws.Cells(ws.Rows.Count, ws.Columns.Count).End(xlUp).Row).ClearContents
For i = 2 To UBound(myarr)
Set xWS = Workbooks.Add
ws.Range(title).AutoFilter Field:=vcol, Criteria1:=myarr(i)
ws.Range("A" & titlerow & ":A" & lr).SpecialCells(xlCellTypeVisible).EntireRow.Copy
xWS.Sheets(1).Cells(1, 1).PasteSpecial Paste:=xlPasteAll
xWS.SaveAs Filename:=savePath & myarr(i) & ".xlsx"
xWS.Close SaveChanges:=False
Next i
ws.AutoFilterMode = False
Application.DisplayAlerts = True
ws.Activate
End Sub
3. Yna, pwyswch F5 key to run the code, and a prompt box is popped out to remind you select the header row, and then, click OK. Gweler y screenshot:
4. In the second prompt box, please select the column data that you want to split based on, then, click OK. Gweler y screenshot:
5. After splitting, all data in the active worksheet is divided into multiple workbooks based on the column values. All the split workbooks are saved into the folder you specified. See screenshot:
Erthyglau cysylltiedig:
- Rhannwch ddata yn daflenni gwaith lluosog yn ôl rhesi cyfrif
- Gall rhannu ystod ddata fawr yn effeithlon yn daflenni gwaith Excel lluosog yn seiliedig ar gyfrif rhes penodol symleiddio rheoli data. Er enghraifft, gall rhannu set ddata bob 5 rhes yn dudalennau lluosog ei gwneud yn fwy hylaw a threfnus. Mae'r canllaw hwn yn cynnig dau ddull ymarferol o gyflawni'r dasg hon yn gyflym ac yn hawdd.
- Cyfuno dau dabl neu fwy yn un yn seiliedig ar golofnau allweddol
- Gan dybio bod gennych dri thabl mewn llyfr gwaith, nawr, rydych chi am uno'r tablau hyn yn un tabl yn seiliedig ar y colofnau allweddol cyfatebol i gael y canlyniad fel y dangosir isod y screenshot. Efallai bod hon yn dasg drafferthus i'r mwyafrif ohonom, ond, peidiwch â phoeni, yr erthygl hon, byddaf yn cyflwyno rhai dulliau ar gyfer datrys y broblem hon.
- Split Text Strings by Delimiter into Multiple Rows
- Fel arfer, gallwch ddefnyddio'r nodwedd Testun i Golofn i rannu cynnwys cell yn golofnau lluosog gan amffinydd penodol, megis coma, dot, hanner colon, slaes, ac ati. Ond, weithiau, efallai y bydd angen i chi rannu cynnwys y gell amffiniedig yn rhesi lluosog ac ailadrodd y data o golofnau eraill fel y sgrinlun a ddangosir isod. A oes gennych unrhyw ffyrdd da o ddelio â'r dasg hon yn Excel? Bydd y tiwtorial hwn yn cyflwyno rhai dulliau effeithiol i gwblhau'r swydd hon yn Excel.
- Split multiline cell contents into separated rows/columns
- Gan dybio bod gennych gynnwys cell aml-linell sydd wedi'i wahanu gan Alt + Enter, a nawr bod angen i chi rannu'r cynnwys aml-linell i resi neu golofnau wedi'u gwahanu, beth allwch chi ei wneud? Yn yr erthygl hon, byddwch yn dysgu sut i rannu cynnwys celloedd aml-linell yn gyflym yn rhesi neu golofnau ar wahân.
Offer Cynhyrchiant Swyddfa Gorau
Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser. Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...
Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn Gwneud Eich Gwaith yn Haws o lawer
- Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
- Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
- Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!