Μετάβαση στο κύριο περιεχόμενο

Πώς να συνενώσετε κελιά εάν υπάρχει ίδια τιμή σε άλλη στήλη στο Excel;

Όπως φαίνεται στο παρακάτω στιγμιότυπο οθόνης, εάν θέλετε να συνδέσετε κελιά στη δεύτερη στήλη με βάση τις ίδιες τιμές στην πρώτη στήλη, υπάρχουν πολλές μέθοδοι που μπορείτε να χρησιμοποιήσετε. Σε αυτό το άρθρο, θα παρουσιάσουμε τρεις τρόπους για να ολοκληρώσετε αυτήν την εργασία.

συνδυάστε αν είναι ίδιο


Συγκεντρώστε τα κελιά εάν έχουν την ίδια τιμή με τύπους και φίλτρο

Οι παρακάτω τύποι βοηθούν στη σύνδεση των περιεχομένων των αντίστοιχων κελιών σε μια στήλη με βάση την ίδια τιμή σε μια άλλη στήλη.

1. Επιλέξτε ένα κενό κελί εκτός από τη δεύτερη στήλη (εδώ επιλέγουμε το κελί C2), εισάγετε τον τύπο = IF (A2 <> A1, B2, C1 & "," & B2) στη γραμμή τύπων και, στη συνέχεια, πατήστε το εισάγετε κλειδί.

2. Στη συνέχεια, επιλέξτε το κελί C2 και σύρετε τη λαβή πλήρωσης προς τα κάτω στα κελιά που πρέπει να συνενώσετε.

3. Εισαγάγετε τον τύπο = IF (A2 <> A3, ΣΥΓΚΕΝΤΡΩΣΗ (A2, "," "", C2, "" ""), "") στο κελί D2 και σύρετε το Fill Handle προς τα κάτω στα υπόλοιπα κελιά.

4. Επιλέξτε το κελί D1 και κάντε κλικ στο ημερομηνία > Φίλτρα. Δείτε το στιγμιότυπο οθόνης:

5. Κάντε κλικ στο αναπτυσσόμενο βέλος στο κελί D1, καταργήστε την επιλογή του (Κενά) πλαίσιο και, στη συνέχεια, κάντε κλικ στο OK κουμπί.

Μπορείτε να δείτε τα κελιά να συνενώνονται εάν οι τιμές της πρώτης στήλης είναι ίδιες.

Note: Για να χρησιμοποιήσετε τους παραπάνω τύπους με επιτυχία, οι ίδιες τιμές στη στήλη Α πρέπει να είναι συνεχείς.


Συνδυάστε εύκολα κελιά εάν η ίδια τιμή με το Kutools για Excel (αρκετά κλικ)

Η μέθοδος που περιγράφεται παραπάνω απαιτεί τη δημιουργία δύο βοηθητικών στηλών και περιλαμβάνει πολλά βήματα, τα οποία μπορεί να είναι άβολα. Αν ψάχνετε για έναν απλούστερο τρόπο, σκεφτείτε να χρησιμοποιήσετε το Σύνθετες σειρές συνδυασμού εργαλείο από Kutools για Excel. Με λίγα μόνο κλικ, αυτό το βοηθητικό πρόγραμμα σάς επιτρέπει να συνενώνετε κελιά χρησιμοποιώντας έναν συγκεκριμένο οριοθέτη, κάνοντας τη διαδικασία γρήγορη και χωρίς προβλήματα.

Άκρο: Πριν εφαρμόσετε αυτό το εργαλείο, εγκαταστήστε το Kutools για Excel Πρώτα. Μεταβείτε στη δωρεάν λήψη τώρα.

1. κλικ Kutools > Συγχώνευση & διαχωρισμός > Σύνθετες σειρές συνδυασμού για να ενεργοποιήσετε αυτήν τη λειτουργία.
2. Στο Σύνθετες σειρές συνδυασμού παράθυρο διαλόγου, το μόνο που χρειάζεται είναι:
  • Επιλέξτε το εύρος που θέλετε να συνδέσετε.
  • Ορίστε τη στήλη με τις ίδιες τιμές με το Πρωτεύων κλειδί στήλη.
  • Καθορίστε ένα διαχωριστικό για να συνδυάσετε τα κελιά.
  • Πατήστε OK.

Αποτέλεσμα

Note:

Συγκεντρώστε τα κελιά εάν έχουν την ίδια τιμή με τον κώδικα VBA

Μπορείτε επίσης να χρησιμοποιήσετε τον κώδικα VBA για να συνδέσετε κελιά σε μια στήλη, εάν η ίδια τιμή υπάρχει σε άλλη στήλη.

1. Τύπος άλλος + F11 για να ανοίξετε το Εφαρμογές της Microsoft Visual Basic παράθυρο.

2. Στο Εφαρμογές της Microsoft Visual Basic παράθυρο, κάντε κλικ στην επιλογή Κύριο θέμα > Μονάδα μέτρησης. Στη συνέχεια, αντιγράψτε και επικολλήστε τον παρακάτω κώδικα στο Μονάδα μέτρησης παράθυρο.

Κωδικός VBA: συνενώστε κελιά εάν έχουν ίδιες τιμές

Sub ConcatenateCellsIfSameValues()
	Dim xCol As New Collection
	Dim xSrc As Variant
	Dim xRes() As Variant
	Dim I As Long
	Dim J As Long
	Dim xRg As Range
	xSrc    = Range("A1", Cells(Rows.Count, "A").End(xlUp)).Resize(, 2)
	Set xRg = Range("D1")
	On Error Resume Next
	For I = 2 To UBound(xSrc)
		xCol.Add xSrc(I, 1), TypeName(xSrc(I, 1)) & CStr(xSrc(I, 1))
	Next I
	On Error GoTo 0
	ReDim xRes(1 To xCol.Count + 1, 1 To 2)
	xRes(1, 1) = "No"
	xRes(1, 2) = "Combined Color"
	For I = 1 To xCol.Count
		xRes(I + 1, 1) = xCol(I)
		For J = 2 To UBound(xSrc)
			If xSrc(J, 1) = xRes(I + 1, 1) Then
				xRes(I + 1, 2) = xRes(I + 1, 2) & ", " & xSrc(J, 2)
			End If
		Next J
		xRes(I + 1, 2) = Mid(xRes(I + 1, 2), 2)
	Next I
	Set xRg = xRg.Resize(UBound(xRes, 1), UBound(xRes, 2))
	xRg.NumberFormat = "@"
	xRg = xRes
	xRg.EntireColumn.AutoFit
End Sub

Notes:

1. D1 στη γραμμή Ορισμός xRg = Εύρος ("D1") σημαίνει ότι το αποτέλεσμα θα τοποθετηθεί ξεκινώντας από το κελί D1.
2. »Οχι" και "Συνδυασμένο χρώμα" στη γραμμή xRes (1, 1) = "Όχι" και xRes (1, 2) = "Συνδυασμένο χρώμα" είναι οι κεφαλίδες των επιλεγμένων στηλών. 

3. Πάτα το F5 κλειδί για να εκτελέσετε τον κώδικα, τότε θα λάβετε τα συνδυασμένα αποτελέσματα σε καθορισμένο εύρος.


Συνδυάστε εύκολα κελιά εάν η ίδια τιμή με το Kutools για Excel

Τα καλύτερα εργαλεία παραγωγικότητας γραφείου

🤖 Kutools AI Aide: Επανάσταση στην ανάλυση δεδομένων με βάση: Ευφυής Εκτέλεση   |  Δημιουργία κώδικα  |  Δημιουργία προσαρμοσμένων τύπων  |  Αναλύστε δεδομένα και δημιουργήστε γραφήματα  |  Επίκληση Λειτουργιών Kutools...
Δημοφιλή χαρακτηριστικά: Εύρεση, επισήμανση ή αναγνώριση διπλότυπων   |  Διαγραφή κενών γραμμών   |  Συνδυάστε στήλες ή κελιά χωρίς απώλεια δεδομένων   |   Γύρος χωρίς φόρμουλα ...
Σούπερ Αναζήτηση: VLookup πολλαπλών κριτηρίων    VLookup πολλαπλών τιμών  |   VLookup σε πολλά φύλλα   |   Ασαφής αναζήτηση ....
Σύνθετη αναπτυσσόμενη λίστα: Γρήγορη δημιουργία αναπτυσσόμενης λίστας   |  Εξαρτημένη αναπτυσσόμενη λίστα   |  Πολλαπλή αναπτυσσόμενη λίστα ....
Διαχειριστής στήλης: Προσθέστε έναν συγκεκριμένο αριθμό στηλών  |  Μετακίνηση στηλών  |  Εναλλαγή κατάστασης ορατότητας κρυφών στηλών  |  Συγκρίνετε εύρη και στήλες ...
Επιλεγμένα Χαρακτηριστικά: Εστίαση πλέγματος   |  Προβολή σχεδίου   |   Μεγάλη Formula Bar    Διαχείριση βιβλίου εργασίας & φύλλου   |  Βιβλιοθήκη πόρων (Αυτόματο κείμενο)   |  Επιλογή ημερομηνίας   |  Συνδυάστε φύλλα εργασίας   |  Κρυπτογράφηση/Αποκρυπτογράφηση κελιών    Αποστολή email ανά λίστα   |  Σούπερ φίλτρο   |   Ειδικό φίλτρο (φίλτρο με έντονη γραφή/πλάγια γραφή/διαγραφή...) ...
Κορυφαία 15 σύνολα εργαλείων12 Κείμενο Εργαλεία (Προσθήκη κειμένου, Κατάργηση χαρακτήρων, ...)   |   50 + Διάγραμμα Τύποι (Gantt διάγραμμα, ...)   |   40+ Πρακτικό ΜΑΘΗΜΑΤΙΚΟΙ τυποι (Υπολογίστε την ηλικία με βάση τα γενέθλια, ...)   |   19 Εισαγωγή Εργαλεία (Εισαγωγή κωδικού QR, Εισαγωγή εικόνας από το μονοπάτι, ...)   |   12 Μετατροπή Εργαλεία (Αριθμοί σε λέξεις, Μετατροπή Συναλλάγματος, ...)   |   7 Συγχώνευση & διαχωρισμός Εργαλεία (Σύνθετες σειρές συνδυασμού, Διαίρεση κελιών, ...)   |   ... κι αλλα

Αυξήστε τις δεξιότητές σας στο Excel με τα Kutools για Excel και απολαύστε την αποτελεσματικότητα όπως ποτέ πριν. Το Kutools για Excel προσφέρει πάνω από 300 προηγμένες δυνατότητες για την ενίσχυση της παραγωγικότητας και την εξοικονόμηση χρόνου.  Κάντε κλικ εδώ για να αποκτήσετε τη δυνατότητα που χρειάζεστε περισσότερο...

Περιγραφή


Το Office Tab φέρνει τη διεπαφή με καρτέλες στο Office και κάνει την εργασία σας πολύ πιο εύκολη

  • Ενεργοποίηση επεξεργασίας και ανάγνωσης καρτελών σε Word, Excel, PowerPoint, Publisher, Access, Visio και Project.
  • Ανοίξτε και δημιουργήστε πολλά έγγραφα σε νέες καρτέλες του ίδιου παραθύρου και όχι σε νέα παράθυρα.
  • Αυξάνει την παραγωγικότητά σας κατά 50% και μειώνει εκατοντάδες κλικ του ποντικιού για εσάς κάθε μέρα!
Comments (23)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
thank you very much, the VBA code works very well but I have a question that I can't solve.

NO Color
1 red
1 blue
1 red
1 yellow
2 red
2 yellow


in this case, in column B we have some duplicate colors related to the same number. How can I have an output that only return the values once?

I would like an output like this

NO Color
1 red, blue, yellow
2 red, yellow
This comment was minimized by the moderator on the site
Hi

The second method described in the post can help you solve this problem. After following the steps to specify the settings, checking the Delect Duplicate Values option will delete all duplicates in the combined results.
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/concatenate.png
This comment was minimized by the moderator on the site
Thank you so much for this formula! It saved hours of investigation! Fantastic work :)
This comment was minimized by the moderator on the site
Hi Crystal,

Thanks for your reply. I'll have to put my thinking hat on again...
Thank you
This comment was minimized by the moderator on the site
Hello, the macro above works great! Thank you. Is it anyway possible (I tried, but not successful) to amend it to concatenate column B (description) based on duplicates in column A (HS code) but also taking column C (origin) in the combination?
So description texts concatenate per HS code per origin.
Also column D(quantity) and column E(value) must be summed per HS code and origin.

A B C D E
HS CODE DESCRIPTION ORIGIN QUANTITY VALUE
5407420000 TWEED CN 10 € 150,00
5407420000 COTTON CN 15 € 250,00
5407420000 POLYESTER TW 5 € 130,00
5407420000 ORGANIC COTTON US 18 € 450,00
5407420000 COTTON US 23 € 780,00
5407420000 VELVET DELUXE CN 20 € 380,00
5407420000 COTTON CN 10 € 120,00
5806310000 TWEED JP 15 € 35,00
5806310000 POLYESTER AU 20 € 78,00
5806310000 TWEED AU 25 € 254,00
5806310000 POLYESTER SG 130 € 888,00
5806310000 COTTON EU 120 € 945,00
5806310000 COTTON FABRIC EU 10 € 80,00


Result shopuld be:

5407420000 TWEED, COTTON, VELVET DULUXE, COTTON, CN 55 € 900,00
5407420000 POLYESTER TW 5 € 130,00
5407420000 ORGANIC COTTON, COTTON US 41 € 1230,00
5806310000 TWEED JP 15 € 35,00
5806310000 POLYESTER, TWEED AU 45 € 332,00
5806310000 POLYESTER SG 130 € 888,00
5806310000 COTTON, COTTON FABRIC EU 130 € 1025,00

I hope this possible, thank you!
This comment was minimized by the moderator on the site
Hi Ivar,

Thank you for your comment. I am not able to solve this problem with VBA code yet. Sorry for that.
You can try if the last method can help.
This comment was minimized by the moderator on the site
Hello, how would the VBA code be adjusted if I want to combine cells in column M based on the duplicates in column A?
This comment was minimized by the moderator on the site
Hi Kristin,To combine cells in column M based on the duplicates in column A, try the VBA below.In the code,  O1 is the first cell to output the results; M is the column you will combine based on the duplicates in column A; A1 and A represent the first cell and the column where the duplicates locate; No and Combine color is the header of the columns after concatenating. You can change these variables as needed.<div data-tag="code">Sub ConcatenateCellsIfSameValues()
'Updated by Extendoffice 20211105
Dim xCol As New Collection
Dim xSrc As Variant
Dim xSrcValue As Variant
Dim xRes() As Variant
Dim I As Long
Dim J As Long
Dim xRg As Range
Dim xResultAddress As String
Dim xMergeAddress As String
Dim xUp As Integer

xResultAddress = "O1" 'The cell to output the results
xMergeAddress = "M" 'The column you will combine based on the duplicates in column A

xSrc = Range("A1", Cells(Rows.Count, "A").End(xlUp)).Resize(, 1)
xUp = Range("A1", Cells(Rows.Count, "A").End(xlUp)).Rows.Count
xSrcValue = Range(xMergeAddress & "1:" & xMergeAddress & xUp)

Set xRg = Range(xResultAddress)
On Error Resume Next
For I = 2 To UBound(xSrc)
xCol.Add xSrc(I, 1), TypeName(xSrc(I, 1)) & CStr(xSrc(I, 1))
Next I

On Error GoTo 0
ReDim xRes(1 To xCol.Count + 1, 1 To 2)
xRes(1, 1) = "No"
xRes(1, 2) = "Combined Color"
For I = 1 To xCol.Count
xRes(I + 1, 1) = xCol(I)
For J = 2 To UBound(xSrc)
If xSrc(J, 1) = xRes(I + 1, 1) Then
xRes(I + 1, 2) = xRes(I + 1, 2) & ", " & xSrcValue(J, 1)
End If
Next J
xRes(I + 1, 2) = Mid(xRes(I + 1, 2), 2)
Next I
Set xRg = xRg.Resize(UBound(xRes, 1), UBound(xRes, 2))
xRg.NumberFormat = "@"
xRg = xRes
xRg.EntireColumn.AutoFit
End Sub
This comment was minimized by the moderator on the site
I just wanted to thank you. It wasn't exactly what I wanted but man did it help me figure out what to do.

I have a table where the person's name was in column A, dates in column B and the names of tools they use in the headers of columns C:G . In each column there is a "Y" if they used that tool on that date and blank if they did not. (FYI: the same person can be listed more than once and may have used the same tool more than once) On a separate (summary) page I wanted to list all tools each person used within a date period, only listing each tool they used once, in the same cell. On this page, the person's name was in column A, Types of tools used in column B and the helper columns were in column G:K. Here's what I got:
The first helper column (G2):
=IF(COUNTIFS(Table7[Person's Name],A2,Table7[Screw Driver],"Y",Table7[Date],">="&1/1/20,Table7[Date],"<="&3/31/20),"Screw Driver","")
In the last helper column (K2):
=IF(COUNTIFS(Table7[Person's Name],A2,Table7[Hammer],"Y",Table7[Date],">="&1/1/20,Table7[Date],"<="&3/31/20),IF(J2="","Hammer",J2&"/"&"Hammer"),J2)

In B2 I just entered =K2

Thanks again and I hope this helps someone. EZPD
This comment was minimized by the moderator on the site
Hi, first of all thanks for creating this resource. I have been trying to figure this out for a couple of hours and I'm stuck. I'm using your 'concatenate cells if same value' but my script is looking at column "D" instead of "A. I can't figure out how to get it to use a different column for the data besides the one right next to it. In my cases I want it to look at column "D" to see if the value is the same and if so, it will grab the data from column "H" and put that data from column "H' into a cell in column "J". How do I switch this to use column "H" for the data? Thx


Sub ConcatenateCellsIfSameValues()
Dim xCol As New Collection
Dim xSrc As Variant
Dim xRes() As Variant
Dim I As Long
Dim J As Long
Dim xRg As Range
xSrc = Range("D1", Cells(Rows.Count, "D").End(xlUp)).Resize(, 2)
Set xRg = Range("J1")
On Error Resume Next
For I = 2 To UBound(xSrc)
xCol.Add xSrc(I, 1), TypeName(xSrc(I, 1)) & CStr(xSrc(I, 1))
Next I
On Error GoTo 0
ReDim xRes(1 To xCol.Count + 1, 1 To 2)
xRes(1, 1) = "No"
xRes(1, 2) = "Products"
For I = 1 To xCol.Count
xRes(I + 1, 1) = xCol(I)
For J = 2 To UBound(xSrc)
If xSrc(J, 1) = xRes(I + 1, 1) Then
xRes(I + 1, 2) = xRes(I + 1, 2) & vbCrLf & xSrc(J, 2)
End If
Next J
xRes(I + 1, 2) = Mid(xRes(I + 1, 2), 2)
Next I
Set xRg = xRg.Resize(UBound(xRes, 1), UBound(xRes, 2))
xRg.NumberFormat = "@"
xRg = xRes
xRg.EntireColumn.AutoFit
End Sub
This comment was minimized by the moderator on the site
"I can't figure out how to get it to use a different column for the data besides the one right next to it. In my cases I want it to look at column 'D' to see if the value is the same and if so, it will grab the data from column 'H' and put that data from column 'H' into a cell in column 'J'."

Did you ever figure this out?
This comment was minimized by the moderator on the site
Hi,

looks like 2 of your formulas are wrong :

=IF(A2<>A3,CONCATENATE(A2,",""",C2,""""),""). You need to change "A2" to "D1". As you'll want to add the string to the previous cell.

same goes for this formula :

=IF(A2<>A1,B2,C1 & "," & B2) : Change C1 to D1.


kind regards


Harry
This comment was minimized by the moderator on the site
I use this VBA for lots of my spreadsheets and its great. But the spreadsheets have become very large 50k+ rows and it doesnt seem to be working any more. If I use it on 1000 rows it works fine but large sets of data it cant seem to cope with. No errors just no results. Any help would be appreciated.
This comment was minimized by the moderator on the site
Hi James,
I tested the code as you mentioned, but it still works well in my case even I set the rows to 1000+.
This comment was minimized by the moderator on the site
Using the VBA macro and getting great results, I have tried tweaking it slightly for my needs but cant get it to work so I hope you can help.

Which bit do I change to make it concat a specific column, not the one directly to the right of the xSrc = Range?

Thanks for your great work!
This comment was minimized by the moderator on the site
Or as a better option, if you had 3 columns instead of 2 and found duplicates in column A (like your example) can you concat column B into a cell and column C into a seperate cell? So if you had columns of Number, Colour, Age, could you concat colour and age into different columns upon finding duplicates in Number? Hope that makes sense!
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations