Note: The other languages of the website are Google-translated. Back to English
Se connecter  \/ 
x
or
x
INSCRIPTION  \/ 
x

or

Comment diviser les données en plusieurs feuilles de calcul en fonction de la colonne dans Excel?

Supposons que vous ayez une feuille de calcul avec d'énormes lignes de données et que vous deviez maintenant diviser les données en plusieurs feuilles de calcul en fonction du Nom colonne (voir capture d'écran suivante), et les noms sont saisis au hasard. Vous pouvez peut-être les trier d'abord, puis les copier et les coller une par une dans d'autres nouvelles feuilles de calcul. Mais cela nécessitera votre patience pour copier et coller à plusieurs reprises. Aujourd'hui, je vais parler de quelques astuces rapides pour résoudre cette tâche.

doc fractionner les données par colonnes 1

Divisez les données en plusieurs feuilles de calcul en fonction de la colonne avec le code VBA

Divisez les données en plusieurs feuilles de calcul en fonction de la colonne avec Kutools for Excel


Divisez les données en plusieurs feuilles de calcul en fonction de la colonne avec le code VBA

Si vous souhaitez fractionner les données en fonction de la valeur de la colonne rapidement et automatiquement, le code VBA suivant est un bon choix. Veuillez faire comme ceci:

1. Maintenez le ALT + F11 clés pour ouvrir le Microsoft Visual Basic pour applications fenêtre.

2. Cliquez insérer > Moduleet collez le code suivant dans la fenêtre Module.

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
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. Puis appuyez F5 pour exécuter le code, et une boîte de dialogue s'affiche pour vous rappeler de sélectionner la ligne d'en-tête, voir capture d'écran:

doc fractionner les données par colonnes 7

4. Et puis, cliquez OK bouton, et dans la deuxième boîte de dialogue, sélectionnez les données de colonne que vous souhaitez diviser en fonction, voir capture d'écran:

doc fractionner les données par colonnes 8

5. Puis clique OKet toutes les données de la feuille de calcul active sont divisées en plusieurs feuilles de calcul par la valeur de la colonne. Et les feuilles de calcul fractionnées sont nommées avec les noms des cellules fractionnées. Voir la capture d'écran:

doc fractionner les données par colonnes 2

Notes: Les feuilles de calcul fractionnées sont placées à la fin du classeur où se trouve la feuille de calcul principale.


Divisez les données en plusieurs feuilles de calcul en fonction de la colonne avec Kutools for Excel

En tant que débutant Excel, ce long code VBA est quelque peu difficile pour nous, et la plupart d'entre nous ne savent même pas comment modifier le code selon nos besoins. Ici, je vais vous présenter un outil multifonctionnel -Kutools pour Excel, il est Diviser les données L'utilitaire peut non seulement vous aider à diviser les données en plusieurs feuilles de calcul en fonction de la colonne, mais peut également diviser les données par nombre de lignes.

A Noter:Appliquer cette Diviser les données, tout d'abord, vous devez télécharger le Kutools pour Excel, puis appliquez la fonction rapidement et facilement.

Après l'installation de Kutools pour Excel, veuillez faire comme ceci:

1. Sélectionnez la plage de données que vous souhaitez fractionner.

2. Cliquez Kutools Plus > Feuille > Diviser les données, voir capture d'écran:

doc fractionner les données par colonnes 3

3. Dans le Diviser les données en plusieurs feuilles de calcul boîte de dialogue, vous devez:

1). Sélectionner Colonne spécifique option dans la Fractionner basé sur et choisissez la valeur de colonne sur laquelle vous souhaitez fractionner les données dans la liste déroulante. (Si vos données ont des en-têtes et que vous souhaitez les insérer dans chaque nouvelle feuille de calcul fractionnée, veuillez vérifier Mes données ont des en-têtes option.)

2). Ensuite, vous pouvez spécifier les noms de feuille de calcul fractionnés, sous Nouveau nom de feuille de calcul , spécifiez les règles de noms de feuille de calcul dans Règles liste déroulante, vous pouvez ajouter le Préfixe or Suffixe pour les noms de feuille également.

3). Clique le OK bouton. Voir la capture d'écran:

doc fractionner les données par colonnes 4

4. Désormais, les données sont divisées en plusieurs feuilles de calcul dans un nouveau classeur.

doc fractionner les données par colonnes 5

Cliquez pour télécharger Kutools pour Excel et un essai gratuit maintenant!


Divisez les données en plusieurs feuilles de calcul en fonction de la colonne avec Kutools for Excel

Kutools pour Excel comprend plus de 300 outils Excel pratiques. Essai gratuit sans limitation de 30 jours. Téléchargez la version d'essai gratuite maintenant!


Article connexe:

Comment diviser les données en plusieurs feuilles de calcul par nombre de lignes?


Les meilleurs outils de productivité de bureau

Kutools for Excel résout la plupart de vos problèmes et augmente votre productivité de 80%

  • Réutilisation: Insérer rapidement formules complexes, graphiques et tout ce que vous avez utilisé auparavant; Crypter les cellules avec mot de passe; Créer une liste de diffusion et envoyer des e-mails ...
  • Barre Super Formula (modifiez facilement plusieurs lignes de texte et de formule); Disposition de lecture (lire et modifier facilement un grand nombre de cellules); Coller dans la plage filtrée...
  • Fusionner les cellules / lignes / colonnes sans perdre de données; Contenu des cellules divisées; Combiner des lignes / colonnes en double... Empêcher les cellules en double; Comparer les gammes...
  • Sélectionnez Dupliquer ou Unique Lignes; Sélectionnez les lignes vides (toutes les cellules sont vides); Super Find et Fuzzy Find dans de nombreux classeurs; Sélection aléatoire ...
  • Copie exacte Plusieurs cellules sans changer la référence de formule; Créer automatiquement des références à plusieurs feuilles; Insérer des puces, Cases à cocher et plus encore ...
  • Extrait du texte, Ajouter du texte, Supprimer par position, Supprimer l'espace; Créer et imprimer des sous-totaux de pagination; Conversion entre le contenu et les commentaires des cellules...
  • Super filtre (enregistrer et appliquer des schémas de filtrage à d'autres feuilles); Tri avancé par mois / semaine / jour, fréquence et plus; Filtre spécial par gras, italique ...
  • Combiner des classeurs et des feuilles de travail; Fusionner les tableaux en fonction des colonnes clés; Diviser les données en plusieurs feuilles; Conversion par lots xls, xlsx et PDF...
  • Plus de 300 fonctionnalités puissantes. Prend en charge Office / Excel 2007-2019 et 365. Prend en charge toutes les langues. Déploiement facile dans votre entreprise ou organisation. Essai gratuit de 30 jours. Garantie de remboursement de 60 jours.
onglet kte 201905

Office Tab apporte une interface à onglets à Office et simplifie considérablement votre travail

  • Activer l'édition et la lecture par onglets dans Word, Excel, PowerPoint, Publisher, Access, Visio et Project.
  • Ouvrez et créez plusieurs documents dans de nouveaux onglets de la même fenêtre, plutôt que dans de nouvelles fenêtres.
  • Augmente votre productivité de 50% et réduit des centaines de clics de souris chaque jour!
bas de cabine
Say something here...
symbols left.
You are guest
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.
    Shaul · 26 days ago
  • To post as a guest, your comment is unpublished.
    ciot · 3 months ago
    hi,I 've to do un upgrade in this code. More specific, i have a Dataset("Data") to split in multiple sheet and this code it's good to me. But in my new sheet i don't want all column from the orignal data but only specific column. How can i do?
  • To post as a guest, your comment is unpublished.
    Vanessa · 4 months ago
    Hi there, is there a limit on the number of rows in the worksheet you need to split? 

    I have 150,000 rows, that need to be split into diff worksheets based on name of company - this VBA is not working
    • To post as a guest, your comment is unpublished.
      skyyang · 3 months ago
      Hello, Vanessa,
      If you have tens of thousands rows data need to be split, I will recommend you to use the Kutools for Excel's Split Data feature, with this feature, you can achieve the job quickly and easily. You can download and free trail 30 days. Please try, thank you!
  • To post as a guest, your comment is unpublished.
    Courtney · 4 months ago
    Is there anyway to do this in a way that will maintain the page layout/print set up? header, footer, gridlines, repeat rows, lanscape, narrow margins, fit columns on page, etc?  

  • To post as a guest, your comment is unpublished.
    MIke Merker · 4 months ago
    Just used this today and the VB Script was exactly what I needed.  Thank you!
  • To post as a guest, your comment is unpublished.
    Alberto · 7 months ago
    Hello, I could split the data base! thanks! :)
    But is there any option to keep transferred datas to each excel sheet, if the master sheet is updating daily?
  • To post as a guest, your comment is unpublished.
    Uros D. · 7 months ago
    Hi, question, is there a good way to ONLY bring in certain columns to the split sheets, instead of all?
  • To post as a guest, your comment is unpublished.
    Jesse · 8 months ago
    Dude this is brilliant....saved me many hours of work. Thank you.
  • To post as a guest, your comment is unpublished.
    JD · 8 months ago
    Nothing happens. I run the code, it prompts me for the header & column info, I input it, and then nothing. Not even an error to point me in the right direction.
    • To post as a guest, your comment is unpublished.
      EG · 8 months ago
      I'm running into the same issue.
  • To post as a guest, your comment is unpublished.
    Pratik Trivedi · 11 months ago
    Hi Team,

    Thank you so much for this code it has helped me over the last few months amazingly.

    However, since last month this code has not working for me. It only creates sheets with the name but data, format as well as headers are not carrying over.

    I have changed my computer though not sure if this has to do something with it. I have been using the same code and steps as specified above.

    Please help!

    Thank You!
  • To post as a guest, your comment is unpublished.
    Dom27 · 11 months ago
    Hello.

    I Have problem with borders. In each new table the bottom border is missing.
    Have you got some solution please?
  • To post as a guest, your comment is unpublished.
    soo.kim · 1 years ago
    How can I change to have it paste starting at cell a10 instead of a1 on the new sheets?
  • To post as a guest, your comment is unpublished.
    Jaco van der Merwe · 1 years ago
    Hi there,
    Thank you so much for this post. It is really very helpful.

    I have another situation that requires me to split salary data per department so that each manager will receive a workbook for their team only. I do not mail these out to managers, I simply safe it in their respective folder on the server.

    I use this code, but this code does not split the worksheet into separate files. Can you please help me to modify this code so that it will create separate workbooks for me in the same directory as the master sheet?

    Sub SplitIntoSheets()
    With Application
    .ScreenUpdating = False
    .DisplayAlerts = False
    End With
    ThisWorkbook.Activate
    Sheet1.Activate
    'clearing filter if any
    On Error Resume Next
    Sheet1.ShowAllData
    On Error GoTo 0
    Dim lsrClm As Long
    Dim lstRow As Long
    'counting last used row
    lstRow = Cells(Rows.Count, 1).End(xlUp).Row
    Dim Planners As Range
    Dim clm As String, clmNo As Long
    On Error GoTo handler
    clm = Application.InputBox("From which column you want create files" & vbCrLf & "E.g. A,B,C,AB,ZA etc.")
    clmNo = Range(clm & "1").Column
    Set Planners = Range(clm & "2:" & clm & lstRow)
    'Calling Remove Duplicates to Get Unique Names
    Set Planners = RemoveDuplicates(Planners)
    Call CreateSheets(Planners, clmNo)
    With Application
    .ScreenUpdating = True
    .DisplayAlerts = True
    .AlertBeforeOverwriting = True
    .Calculation = xlCalculationAutomatic
    End With
    Sheet1.Activate
    MsgBox "Well Done!"
    Exit Sub
    Data.ShowAllData
    handler:
    With Application
    .ScreenUpdating = True
    .DisplayAlerts = True
    .AlertBeforeOverwriting = True
    .Calculation = xlCalculationAutomatic
    End With
    End Sub
    Function RemoveDuplicates(Planners As Range) As Range
    ThisWorkbook.Activate
    Sheets.Add
    On Error Resume Next
    ActiveSheet.Name = "Planners"
    Sheets("Planners").Activate
    On Error GoTo 0
    Planners.Copy
    Cells(2, 1).Activate
    ActiveCell.PasteSpecial xlPasteValues
    Range("A1").Value = "Planners"
    Dim lstRow As Long
    lstRow = Cells(Rows.Count, 1).End(xlUp).Row
    Range("A2:A" & lstRow).Select
    ActiveSheet.Range(Selection.Address).RemoveDuplicates Columns:=1, Header:=xlNo
    lstRow = Cells(Rows.Count, 1).End(xlUp).Row
    Set RemoveDuplicates = Range("A2:A" & lstRow)
    End Function
    Sub CreateSheets(Planners As Range, clmNo As Long)
    Dim lstClm As Long
    Dim lstRow As Long

    For Each Unique In Planners
    Sheet1.Activate
    lstRow = Cells(Rows.Count, 1).End(xlUp).Row
    lstClm = Cells(1, Columns.Count).End(xlToLeft).Column
    Dim dataSet As Range
    Set dataSet = Range(Cells(1, 1), Cells(lstRow, lstClm))
    dataSet.AutoFilter field:=clmNo, Criteria1:=Unique.Value
    lstRow = Cells(Rows.Count, 1).End(xlUp).Row
    lstClm = Cells(1, Columns.Count).End(xlToLeft).Column
    Debug.Print lstRow; lstClm
    Set dataSet = Range(Cells(1, 1), Cells(lstRow, lstClm))
    dataSet.Copy
    Sheets.Add
    ActiveSheet.Name = Unique.Value2
    ActiveCell.PasteSpecial xlPasteAll
    Next Unique
    End Sub
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello, Jaco,
      To split the data into multiple separate workbooks based on the column value, the code in the following article may help you:
      https://www.datanumen.com/blogs/2-fast-means-to-split-an-excel-worksheets-contents-into-multiple-workbooks-based-on-a-specific-column/

      Please try it, thank you!
  • To post as a guest, your comment is unpublished.
    Ani · 1 years ago
    Hi, it is working great but I need to keep the header row and the infromation above it in each sheet and also the formatting of the header row.
    Does anyone know how this can happen?


  • To post as a guest, your comment is unpublished.
    Joe · 1 years ago
    This is awesome!! Thank you so much for sharing!
  • To post as a guest, your comment is unpublished.
    Kevin · 1 years ago
    Hey, i really need some help.
    1. first i want to to split based on value and after that to split per 1k based on value before.
    2. After split per 1k, i need to save as those files to xls.

    Can someone help me to solve thats problem
  • To post as a guest, your comment is unpublished.
    nk · 1 years ago
    This macro has come in handy more times than i can count, Does anyone have a work around for these two issues? Any help is appreciated!

    1. make the Macro work form a worksheet that is formatted as a table and maintain the same formatting in the new worksheets? I have been able to use this macro when the worksheet is not formatted.

    2. split columns that Include blank cells from the original worksheet to the new worksheets. My original data has some empty cells, that need to remain empty, when i use this macro, the divided columns exclude the data that had an empty cell in the column that was split.
  • To post as a guest, your comment is unpublished.
    NK · 1 years ago
    This macro has come in handy more times than i can count, Does anyone have a work around for these two issues? Any help is appreciated!

    1. make the Macro work form a worksheet that is formatted as a table and maintain the same formatting in the new worksheets? I have been able to use this macro when the worksheet is not formatted.

    2. split columns that Include blank cells from the original worksheet to the new worksheets. My original data has some empty cells, that need to remain empty, when i use this macro, the divided columns exclude the data that had an empty cell in the column that was split.
  • To post as a guest, your comment is unpublished.
    AshSam123 · 1 years ago
    Hey everyone. I am completely new to VBA. I have an account receivable data in an excel sheet and there are multiple column. One column mention the invoice no and the other mentions the department responsible for that invoice. I have tried this code, it split the column by department into multiple sheets but it does not include the invoice no. I have a big list of data and I don't to want copy and paste the data, can someone please help me. Thanks
    • To post as a guest, your comment is unpublished.
      AshSam123 · 1 years ago
      Thank you for your response. I cannot post the original, but here is the sample data. I hope you can help me. Many Thanks
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hi, Ayesha,
      Could you upload your problem screenshot here? Thank you!
  • To post as a guest, your comment is unpublished.
    Guest25 · 1 years ago
    The vba code is not working if the column values to split on has a length of 26. If I manually change it to 12 it works. Is there a reason for it. I understand that excel worksheet name cannot exceed 30 characters but here the length is 26 but it does not work. Can you please help me understand this. Thanks.
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello,
      Thank you for your comment, yes, as you said, the above vba code is not worked correctlly for cell values which text length are much longer, but, here, you can apply our product, Kutools for Excel, with its Split Data feature, you can achieve this job quickly and easily. You can download and free trail 30 days. Please try, thank you!
  • To post as a guest, your comment is unpublished.
    Melvin · 1 years ago
    the code to split the data works perfectly, except it skips some data and renames these as "sheet#"
  • To post as a guest, your comment is unpublished.
    sha · 1 years ago
    thank you very much, it helped me a lot in my work. However, is there a way to have the macro create a separate spreadsheet for each new tab instead of just adding a tab into the current worksheet? Thanks!
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hi,
      If you want to save each sheet as a new workbbok based on the column value, the following articles may help you! Please check:

      https://www.extendoffice.com/documents/excel/2734-excel-split-data-into-multiple-workbooks.html
      https://www.datanumen.com/blogs/2-fast-means-to-split-an-excel-worksheets-contents-into-multiple-workbooks-based-on-a-specific-column/
  • To post as a guest, your comment is unpublished.
    G · 2 years ago
    How can I make it to automatically choose a smaller name for the sheet instead of skipping an entry and returning sheet 4, sheet 5 etc.

    E.G: I am using this amazing code to dissect my excel sheet, but some entries have a long name which exceeds the sheet name count, instead of using all 31 symbols that are allowed, it cancels the filtering and returns sheet 4 instead.
  • To post as a guest, your comment is unpublished.
    K · 2 years ago
    Could I make it so that I would be able to automatically split it so both Emily and Lucy's are in one page, and Jone and Steven's are in another?
    • To post as a guest, your comment is unpublished.
      skyyang · 2 years ago
      Hi,
      Sorry, at present, maybe there is not a good method for solving your problem. But you can combine the two sheets you need after splitting.
  • To post as a guest, your comment is unpublished.
    Mark · 2 years ago
    This works great but is there a way I can carry over my formulas from the original worksheet?
    • To post as a guest, your comment is unpublished.
      skyyang · 2 years ago
      Hi, Mark,
      The above VBA code helps to keep the formula cells after splitting the data, please try!
      Thank you!
      • To post as a guest, your comment is unpublished.
        Mark · 2 years ago
        Works great!


        Thanks for all your help!
  • To post as a guest, your comment is unpublished.
    Bernhard · 2 years ago
    Thank you, worked excellently!
  • To post as a guest, your comment is unpublished.
    Degardt · 2 years ago
    This code is brilliant. It does exactly what I need. Only, I don't know how to change the code so that the data in the rows, all starting with the same letter, should go on the same worksheet, instead of each getting its own worksheet. I have 1000 rows of data, some starting with "L", or "K"or "F" and then a number. It sorts the data each to its own sheet, I want all the "L" cells' data on one sheet and all the"K" data on one sheet. Can someone please help me. I don't underwstand coding that good
    • To post as a guest, your comment is unpublished.
      MP · 2 years ago
      Add a column and pull the first character from the cell with L+ the number or K+ the number. Assume your key is in cell A2, use the formula =left(A2,1) to pull the first character into your new column. Use this column to separate data to its own sheet.
      • To post as a guest, your comment is unpublished.
        Degardt · 2 years ago
        Thank you MP, I will definitely try that. I'm new to coding and still trying to figure it out as I go. But it's crunch time and i need the program to work ASAP. For now I'm just struggling a bit. Lol
  • To post as a guest, your comment is unpublished.
    Aaron · 2 years ago
    Why does the VBA create new sheets with columns all the way to XFD when my main sheet only goes to AK?
  • To post as a guest, your comment is unpublished.
    ShiroKuro · 2 years ago
    how do i make this work on around 150k rows count. Thanks
    • To post as a guest, your comment is unpublished.
      skyyang · 2 years ago
      Hello, ShiroKuro,
      If there are large data in your worksheet, I recommend Kutools for Excel's Split Data feature for you, you can download it and free trial 60-day!
      Please try, thank you!
  • To post as a guest, your comment is unpublished.
    adityabhatnagar2103@gmail.com · 2 years ago
    Great script! Could someone please help as I need to just add "Class-C" at the end of each new worksheet's name that is created after running this. For Eg. Lucy-Class C; Emily Class C; and so on. Would really appreciate your help here.
    • To post as a guest, your comment is unpublished.
      Me · 2 years ago
      just add a column and concatenate the Name and the "-Class C" field and use that as the column to split on instead of the Name column, then you can hide the column if you want
    • To post as a guest, your comment is unpublished.
      skyyang · 2 years ago
      Hello, Aditya,
      Here, I recommend Kutools for Excel's Split Data feature for you, you can add the prefix or suffix text easily in the dialog box as you need.
      You can download the tool and free trial 60-day.
      Please try, thank you!
  • To post as a guest, your comment is unpublished.
    Katharina · 2 years ago
    Great Script, thanks! What do I have to do to set the header row range and column to use for grouping/splitting within the script? I know it is more elegant to use selectable parameters but for my use case it is always the same. As I do know nothing about VBA, any little hint is appreciated :-) Best, Katharina
  • To post as a guest, your comment is unpublished.
    daiana · 2 years ago
    It doesn't work with 120000 rows. Is there any way to make it work?
  • To post as a guest, your comment is unpublished.
    Radoslav · 2 years ago
    Perfect!!! Works and refer to all my demands. Tnx for that source code.
  • To post as a guest, your comment is unpublished.
    Rudi Miller · 2 years ago
    Sub parse_data()
    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
    vcol = 1
    Set ws = Sheets("Sheet1")
    lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
    title = "A1:C1"
    titlerow = ws.Range(title).Cells(1).Row
    icol = ws.Columns.Count
    ws.Cells(1, icol) = "Unique"
    For i = 2 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
    ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
    Sheets(myarr(i) & "").Columns.AutoFit
    Next
    ws.AutoFilterMode = False
    ws.Activate
    End Sub
  • To post as a guest, your comment is unpublished.
    Jason · 2 years ago
    This formula is great, works perfectly for me.
    I want to split out data based on a location, which is in column 1. Which this does.
    However, is it possible to also split out based on column 2, for example. Built and Not Built. So a secondary condition also?
  • To post as a guest, your comment is unpublished.
    jose · 2 years ago
    can someone help please im using this but i keep getting to many columns. i have to keep deleting rows every time i use this.

    This is what im using


    Sub parse_data()
    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
    vcol = 1
    Set ws = Sheets("sheet1")
    lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
    title = "A1:AN1"
    titlerow = ws.Range(title).Cells(1).Row
    icol = ws.Columns.Count
    ws.Cells(1, icol) = "Unique"
    For i = 2 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
    ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
    Sheets(myarr(i) & "").Columns.AutoFit
    Next
    ws.AutoFilterMode = False
    ws.Activate
    End Sub
  • To post as a guest, your comment is unpublished.
    itsavinash · 2 years ago
    Thanks for VBA, it works great. In addition to that question, I have column which is dependent. So when i select some value my column values get changed hence I need vba solution to replace earlier split worksheet to replace with new value of columns. Can anyone help me out.?

    Thanks in advance
  • To post as a guest, your comment is unpublished.
    JP Tontegode · 2 years ago
    Is there a way to have the macro create a separate spreadsheet for each new tab instead of just adding a tab into the current worksheet? Thanks!
  • To post as a guest, your comment is unpublished.
    Sebastian · 2 years ago
    Effectively, this code does work great. I wrote an additional code so that I could get subtotal on certain columns but it has not worked great. So I tried running the subtotals from the master list, but afterwards when I use this macro it create a whole new tab for the Grand total row. So I am getting two two tabs per split. the first one is fine because it splits with the grand totals, but then creates a second one with just the grand total row. Any help as to how to modify this.
    This is the code that I am currently using:
    Sub parse_data()
    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
    vcol = 3
    Set ws = Sheets("Master sheet")
    lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
    title = "A1:R1"
    titlerow = ws.Range(title).Cells(1).Row
    icol = ws.Columns.Count
    ws.Cells(1, icol) = "Unique"
    For i = 2 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
    ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
    Sheets(myarr(i) & "").Columns.AutoFit
    Next
    ws.AutoFilterMode = False
    ws.Activate
    End Sub
  • To post as a guest, your comment is unpublished.
    Jenny Singleton · 2 years ago
    Hi, This VBA worked great on my first attempt. However, when repeating the process with a new set of data, the sheets are splitting into Product names, but the data in each sheet still shows all data. I can't understand why it worked first time though. Can anyone help please. Thanks
  • To post as a guest, your comment is unpublished.
    Trisha · 2 years ago
    This code is brilliant - Thank you. Just one thing - its splitting the data as I need it too but amongst creating the relevant sheets its creating blank sheets too.


    Are you able to help with this?
  • To post as a guest, your comment is unpublished.
    aaseef.khan@gmail.com · 2 years ago
    Thanks for the Magic Words
  • To post as a guest, your comment is unpublished.
    Muhammad Jahanzaib · 3 years ago
    Thanks for excellent & brilliant code. I came across a bug, if field name is too long, the new sheet is not created. It should be like that the new sheet may be named with the maximum number of characters allowed. Regards,
  • To post as a guest, your comment is unpublished.
    Alex S · 3 years ago
    To anyone having issues with long sheet names (ie Sheet Names greater than 30 characters), replace:

    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
    ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
    Sheets(myarr(i) & "").Columns.AutoFit
    Next

    with

    Dim sheetName As String
    For i = 2 To UBound(myarr)
    ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
    ' Replace the below assignment to sheetName as you wish
    sheetName = Left(CStr(i - 1) & "_" & myarr(i), 30)
    If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
    Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = sheetName
    Else
    Sheets(sheetName).Move after:=Worksheets(Worksheets.Count)
    End If
    ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(sheetName).Range("A1")
    Sheets(sheetName).Columns.AutoFit
    Next

    This essentially limits the Sheet Name to legal limits of 30 characters. If you do not like the way the sheet is named, replace sheetName's assignment whatever you would like, keeping in mind that no two sheets can have the exact same name and must also be 30 characters or less.

    You can also remove the filtering that lingers at the end of the execution by adding this line just before "End Sub"

    On Error Resume Next
    ActiveSheet.ShowAllData

    Enjoy ^_^
  • To post as a guest, your comment is unpublished.
    prdpsharma90@gmail.com · 3 years ago
    I have used this VBA code, its split the data but split whole data in new sheet instead of unique value.
  • To post as a guest, your comment is unpublished.
    Pradeep Sharma · 3 years ago
    The VBA code split the data perfectly but its split the whole data instead of unique value.
  • To post as a guest, your comment is unpublished.
    Jorge Portillo · 3 years ago
    The codes works perfectly, only trouble is that it does not separate columns when the text is too long, I have text with 40 characters and I get an empty "sheet2", every other text gets sorted.


    Any ideas on how to fix it? I've already tried changin variable and placed them as Long, however I am not sure I fully understand the program. all this for the VBA option.
  • To post as a guest, your comment is unpublished.
    Manish · 3 years ago
    I need a macro for following condition
    suppose i have customer excel file in which first 7 rows is for header so, from 8th row records are start
    i need to split rows of 500 record each in one file and save them with name customer1,customer2,customer3,........
    suppose i have customer file of 2540 records so it split in
    customer1 which have header rows with record starts from 8th row to 507th row
    customer2 which have header rows with record starts from 508th row to 1007th row
    customer3 which have header rows with record starts from 1008th row to 1507th row
    customer4 which have header rows with record starts from 1508th row to 2007th row
    customer5 which have header rows with record starts from 2008th row to 2507th row
    customer6 which have header rows with record starts from 2508th row to 2540th row
    • To post as a guest, your comment is unpublished.
      hipppar@gmail.com · 2 years ago
      hi. I have similar situation, I want to keep first 8 rows in every sheet created. did you find any solution to this?
      • To post as a guest, your comment is unpublished.
        skyyang · 2 years ago
        Hi, guys,
        If your worksheet data contains multiple header rows, the below VBA code can solve your prolem, please try it.

        Sub Parse_data_0213()
        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

        Hope it can help you, thank you!
  • To post as a guest, your comment is unpublished.
    Dilusha · 3 years ago
    How can I get the Total of Column C for each sheets.?