Note: The other languages of the website are Google-translated. Back to English

Hoe rijen samen te voegen tot één cel op basis van een groep in Excel?

Hier is een reeks van twee kolommen: de ene is de klassenlijst en de andere is de lijst met leerlingnamen. Zoals u ziet, zitten sommige studenten in dezelfde klas, andere niet. Nu wil ik de studenten in dezelfde klas in één cel samenvoegen, zoals onderstaand screenshot laat zien, hoe kan ik dit snel in Excel afhandelen?
doc aaneenschakelen per groep 1

Groeperen en samenvoegen met formules en filterfunctie

Groepeer en voeg samen met VBA-code

Groepeer en voeg samen met Advanced Combine Rowsgoed idee 3


Groeperen en samenvoegen met formules en filterfunctie

In Excel kunt u formules toepassen op aaneengeschakelde rijen op basis van één kolom en vervolgens de filterfunctie gebruiken om alleen het resultaat weer te geven.

Opmerking:: U moet uw gegevens sorteren op klas voordat u de stappen volgt.

1. Typ deze formule in een lege cel naast het gegevensbereik, bijvoorbeeld C13 =IF(A13=A12,C12&", "&B13,B13), druk op Enter toets en vul de formule in cellen met de slepende vulgreep.
doc aaneenschakelen per groep 2

In de formule is A13 de eerste gegevens in de kolom "Klasse", B13 is de eerste gegevens in de kolom "Naam", "," is het scheidingsteken om de samengevoegde inhoud af te bakenen.

2. Typ deze formule vervolgens in de volgende kolom, D13 =IF(A13<>A14,"Last","") en sleep de vulgreep omlaag om de formule toe te passen op de cellen die u nodig hebt.
doc aaneenschakelen per groep 3

3. Selecteer nu alle gegevensreeksen inclusief formules en klik op Data > Filter toevoegen Filter icons naar de gegevens.
doc aaneenschakelen per groep 4

4. Klik op het Filter icon controleer in de laatste formulekop Last selectievakje alleen in de vervolgkeuzelijst en klik op OK.
doc aaneenschakelen per groep 5

Nu wordt het resultaat weergegeven zoals hieronder, u kunt de laatste hulpkolom verwijderen als u deze nooit nodig heeft.
doc aaneenschakelen per groep 6


Groepeer en voeg samen met VBA-code

Hier is een VBA-code die deze taak ook aankan.

1. druk op Alt + F11 toetsen om het Microsoft Visual Basic for Applications venster.

2. Klik vervolgens in het venster op Tools > References in staat te stellen References dialoogvenster en vink aan Microsoft Scripting Runtime. Zie screenshot:
doc aaneenschakelen per groep 7
doc aaneenschakelen per groep 8

3. klikken OKen klik Insert > Module in VBA-venster en kopieer en plak onder VBA-code naar het Module script. Zie screenshot:

VBA: rijen samenvoegen tot één cel op basis van groep

  Sub ConcatenateCellsIfSameValues()
'UpdatebyExtendoffice20180201
    Dim I As Long
    Dim J As Long
    Dim xRg As Range
    Dim xRgKey As Range
    Dim xRgVal As Range
    Dim xStr As String
    Dim xDic As New Dictionary
    On Error Resume Next
    Set xRg = Application.InputBox("Select data range", "KuTools for Excel", Selection.Address, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    Set xRgKey = Application.InputBox("Select key column", "KuTools for Excel", xRg.Columns(1).Address, , , , , 8)
    If xRgKey Is Nothing Then
        MsgBox "Key column cannot be empty", vbInformation, "KuTools for Excel"
    End If
    Set xRgVal = xRg(1).Offset(, 1).Resize(xRg.Rows.Count, xRg.Columns.Count - 1)
    For I = 1 To xRgKey.Count
        If I > xRgKey.Count Then Exit For
        xStr = ""
        For J = 1 To xRgVal.Columns.Count
            xStr = xStr & " " & xRgVal(I, J)
        Next
        If xDic.Exists(xRgKey(I).Text) Then
            xDic(xRgKey(I).Text) = xDic(xRgKey(I).Text) & xStr
            xRgKey(I).EntireRow.Delete
            I = I - 1
       Else
            xDic.Add xRgKey(I).Text, xStr
        End If
    Next
    For I = 1 To xRgVal.Count
        xRgVal(I).Value = xDic(xRgKey(I).Text)
    Next
End Sub

doc concatenate by group 9

4. Press F5 key, and select the data range you use in the popping dialog.
doc concatenate by group 10

5. Click OK to select the key column you want to group based on.
doc concatenate by group 11

6. Click OK, now the result is shown as below:
doc concatenate by group 12


Group and concatenate with Advanced Combine Rows

Here is a utility in Kutools for Excel, Advanced Combine Rows, which can combine rows or do calculations based on a key column in Excel.

Kutools for Excel, with more than 300 handy functions, makes your jobs more easier. 

After installing Kutools for Excel, please do as below:(Free Download Kutools for Excel Now!)

1. Select the data range you use and click Kutools > Merge & Split > Advanced Combine Rows.
doc concatenate by group 13

2. In the Advanced Combine Rows window, choose the column which you want to combine rows based on, and click Primary Key to set it as key column.
doc concatenate by group 14

3. Select the column you need to combine, click Combine, and choose one delimiter you use to separate the combined contents.

doc concatenate by group 15 doc arrow right doc concatenate by group 16

4. Click Ok. The result is shown as this:
doc concatenate by group 17

Note: Before apply the utility, you had better have a copy of the original data.


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Comments (2)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
la formule excel d&eacute;taill&eacute;e plus haut ne fonctionne pas, il y a un probl&egrave;me=IF(A13=A12,C12&amp;", "&amp;B13,B13)
NADIA TSOULI
This comment was minimized by the moderator on the site
Hi, could you repeat the qustion in English? This formula I have tried again, it is correct.
Sunny
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0  Characters
Suggested Locations