Skip i'r prif gynnwys

Sut i gyd-fynd yn hawdd â thestun yn seiliedig ar feini prawf yn Excel?

Gan dybio bod gen i golofn o rifau adnabod sy'n cynnwys rhai dyblygu a cholofn o enwau, ac yn awr, rydw i am gyd-fynd â'r enwau yn seiliedig ar y rhifau adnabod unigryw fel y dangosir y llun chwith, er mwyn cyfuno'r testun yn gyflym yn seiliedig ar feini prawf, sut allen ni wneud yn Excel?

doc cyfuno testun yn seiliedig ar feini prawf 1

Testun concatenate yn seiliedig ar feini prawf gyda Swyddogaeth Diffiniedig Defnyddiwr

Concatenate testun yn seiliedig ar feini prawf gyda Kutools ar gyfer Excel


I gyfuno testun â'r rhifau adnabod unigryw, gallwch echdynnu'r gwerthoedd unigryw yn gyntaf ac yna creu Swyddogaeth Diffiniedig Defnyddiwr i gyfuno'r enwau yn seiliedig ar yr ID unigryw.

1. Cymerwch y data canlynol fel enghraifft, mae angen i chi echdynnu'r rhifau adnabod unigryw yn gyntaf, defnyddiwch y fformiwla arae hon: =IFERROR(INDEX($A$2:$A$15, MATCH(0,COUNTIF($D$1:D1, $A$2:$A$15), 0)),""), Rhowch y fformiwla hon i mewn i gell wag, D2 er enghraifft, yna pwyswch Ctrl + Shift + Enter allweddi gyda'i gilydd, gweler y screenshot:

doc cyfuno testun yn seiliedig ar feini prawf 2

Tip: Yn y fformiwla uchod, A2: A15 yw'r ystod ddata rhestr rydych chi am dynnu gwerthoedd unigryw ohoni, D1 yw cell gyntaf y golofn rydych chi am roi'r canlyniad echdynnu allan.

2. Ac yna llusgwch y ddolen llenwi i lawr i echdynnu'r holl werthoedd unigryw nes bod bylchau wedi'u harddangos, gweler y screenshot:

doc cyfuno testun yn seiliedig ar feini prawf 3

3. Yn y cam hwn, dylech greu a Swyddogaeth Diffiniedig Defnyddiwr i gyfuno'r enwau yn seiliedig ar y rhifau adnabod unigryw, daliwch y ALT + F11 allweddi, ac mae'n agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

4. Cliciwch Mewnosod > Modiwlau, a gludwch y cod canlynol yn y Modiwlau Ffenestr.

Cod VBA: testun cyd-fynd yn seiliedig ar feini prawf

Function ConcatenateIf(CriteriaRange As Range, Condition As Variant, ConcatenateRange As Range, Optional Separator As String = ",") As Variant
'Updateby Extendoffice
Dim xResult As String
On Error Resume Next
If CriteriaRange.Count <> ConcatenateRange.Count Then
    ConcatenateIf = CVErr(xlErrRef)
    Exit Function
End If
For i = 1 To CriteriaRange.Count
    If CriteriaRange.Cells(i).Value = Condition Then
        xResult = xResult & Separator & ConcatenateRange.Cells(i).Value
    End If
Next i
If xResult <> "" Then
    xResult = VBA.Mid(xResult, VBA.Len(Separator) + 1)
End If
ConcatenateIf = xResult
Exit Function
End Function

5. Yna arbed a chau'r cod hwn, ewch yn ôl i'ch taflen waith, a nodi'r fformiwla hon yng nghell E2, = CONCATENATEIF ($ A $ 2: $ A $ 15, D2, $ B $ 2: $ B $ 15, ",") , gweler y screenshot:

doc cyfuno testun yn seiliedig ar feini prawf 4

6. Yna llusgwch y handlen llenwi i lawr i'r celloedd rydych chi am gymhwyso'r fformiwla hon, ac mae'r holl enwau cyfatebol wedi'u cyfuno yn seiliedig ar y rhifau adnabod, gweler y screenshot:

doc cyfuno testun yn seiliedig ar feini prawf 5

Awgrym:

1. Yn y fformiwla uchod, A2: A15 yw'r data gwreiddiol yr ydych am ei gyfuno yn seiliedig ar, D2 yw'r gwerth unigryw rydych chi wedi'i dynnu, a B2: B15 yw'r golofn enw rydych chi am ei chyfuno gyda'ch gilydd.

2. Fel y gallwch weld, fe wnes i gyfuno'r gwerthoedd sy'n cael eu gwahanu gan atalnod, gallwch ddefnyddio unrhyw nodau eraill trwy newid coma “,” y fformiwla yn ôl yr angen.


Os oes gennych Kutools ar gyfer Excel, Gyda'i Rhesi Cyfuno Uwch cyfleustodau, gallwch chi gyd-fynd yn gyflym ac yn gyfleus â sylfaen y testun ar feini prawf.

Kutools ar gyfer Excel : gyda mwy na 300 o ychwanegiadau Excel defnyddiol, am ddim i geisio heb unrhyw gyfyngiad mewn 30 diwrnod.

Ar ôl gosod Kutools ar gyfer Excel, gwnewch fel y camau canlynol:

1. Dewiswch yr ystod ddata rydych chi am ei chyfuno yn seiliedig ar un golofn.

2. Cliciwch Kutools > Uno a Hollti > Rhesi Cyfuno Uwch, gweler y screenshot:

3. Yn y Cyfuno Rhesi Yn Seiliedig ar Golofn blwch deialog, cliciwch y golofn ID ac yna cliciwch Allwedd Cynradd i wneud y golofn hon fel y golofn allweddol y mae eich data cyfun yn seiliedig arni, gweler y screenshot:

doc cyfuno testun yn seiliedig ar feini prawf 7

4. Ac yna cliciwch Enw colofn yr ydych am gyfuno'r gwerthoedd, yna cliciwch Cyfunwch opsiwn, a dewis un gwahanydd ar gyfer y data cyfun, gweler y screenshot:

doc cyfuno testun yn seiliedig ar feini prawf 8

5. Ar ôl gorffen y gosodiadau hyn, cliciwch OK i adael y dialog, ac mae'r data yng ngholofn B wedi'i gyfuno gyda'i gilydd yn seiliedig ar golofn allweddol A. Gweler y screenshot:

doc cyfuno testun yn seiliedig ar feini prawf 9

Gyda'r nodwedd hon, bydd y broblem ganlynol yn cael ei datrys cyn gynted â phosibl:

Sut i gyfuno rhesi lluosog yn un a dyblygu swm yn Excel?

Dadlwythwch a threial am ddim Kutools ar gyfer Excel Nawr !


Kutools ar gyfer Excel: gyda mwy na 300 o ychwanegiadau Excel defnyddiol, am ddim i geisio heb unrhyw gyfyngiad mewn 30 diwrnod. Dadlwythwch a threial am ddim Nawr!

Offer Cynhyrchiant Swyddfa Gorau

🤖 Kutools AI Aide: Chwyldro dadansoddi data yn seiliedig ar: Cyflawniad Deallus   |  Cynhyrchu Cod  |  Creu Fformiwlâu Personol  |  Dadansoddi Data a Chynhyrchu Siartiau  |  Invoke Swyddogaethau Kutools...
Nodweddion Poblogaidd: Darganfod, Amlygu neu Adnabod Dyblygiadau   |  Dileu Rhesi Gwag   |  Cyfuno Colofnau neu Gelloedd heb Colli Data   |   Rownd heb Fformiwla ...
Super-edrych: VLookup Meini Prawf Lluosog    VLookup Gwerth Lluosog  |   VLookup Ar Draws Taflenni Lluosog   |   Edrych Niwlog ....
Rhestr gwympo Uwch: Creu Rhestr Gollwng yn Gyflym   |  Rhestr Gollwng Dibynnol   |  Rhestr Gollwng Aml-ddewis ....
Rheolwr Colofn: Ychwanegu Nifer Penodol o Golofnau  |  Symud Colofnau  |  Toglo Statws Gwelededd Colofnau Cudd  |  Cymharwch Ystodau a Cholofnau ...
Nodweddion dan Sylw: Ffocws ar y Grid   |  Golwg Dylunio   |   Bar Fformiwla Mawr    Rheolwr Llyfr Gwaith a Thaflen   |  Llyfrgell Adnoddau (Testun Auto)   |  Dewiswr Dyddiad   |  Cyfuno Taflenni Gwaith   |  Amgryptio/Dadgryptio Celloedd    Anfon E-byst trwy Restr   |  Hidlo Super   |   Hidlo Arbennig (hidlo mewn print trwm/italig/strikethrough...) ...
15 Set Offer Gorau12 Testun offer (Ychwanegu Testun, Dileu Cymeriadau,...)   |   50 + Siart Mathau (Siart Gantt,...)   |   40+ Ymarferol Fformiwlâu (Cyfrifwch oedran yn seiliedig ar ben-blwydd,...)   |   19 mewnosod offer (Mewnosod Cod QR, Mewnosod Llun o'r Llwybr,...)   |   12 Trosi offer (Rhifau i Eiriau, Trosi arian cyfred,...)   |   7 Uno a Hollti offer (Rhesi Cyfuno Uwch, Celloedd Hollt,...)   |   ... a mwy

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...

Disgrifiad


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!
Comments (38)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Great function! Is there a way to maintain the format in the cell it's concatenating data from? i.e. $45.07, $555.34, $0.00, $0.25, -$12.25 I've figured out how to stack them with wrap text and CHAR(10) in place of "," but having trouble keeping the format. I will be using this for a mail merge in Word.
This comment was minimized by the moderator on the site
Hello, Laurie,If you want to keep the cell formatting when concatenating the data, you can apply the Advanced Combine Rows feature of Kutools for Excel, in the dialog box, after finishing the settings, you just need to check Use formatted values option, and all the data formatting will be kept as you need.
You can download Kutools for Excel and free trial 30-day.
This comment was minimized by the moderator on the site
Is there any way to add "and" instead of "," before the last data? (For example: D2355, D2273, D2397, D2600 and D2386)
This comment was minimized by the moderator on the site
Hi, Hossain,May be there is not a direct method for solving your problem, you can add another formula to convert the last comma to the text "and".=SUBSTITUTE(E2,","," and ",LEN(E2)-LEN(SUBSTITUTE(E2,",","")))
Please try, thank you!
This comment was minimized by the moderator on the site
It worked like a charm sir. Thank you so much.
This comment was minimized by the moderator on the site
Great function, exactly what I needed! Works like a charm
This comment was minimized by the moderator on the site
Hi,

Very helpful VBA solution. Thank you kindly! My question is: Is there a way to change the code or function for multiple criteria? Although the code works for me, I need it to show values corresponding to a timestamp-interval (>= timestamp A, <= timestamp B)


Thank you in advance. :)
This comment was minimized by the moderator on the site
Is there a way to assign this to a button? On large data ranges it takes a while, so ideally I only want it to start the concatenate process once I've finished doing everything else in the sheet. I tried adding a trigger myself but it stopped working completely
This comment was minimized by the moderator on the site
BTW i used the VBA solution
This comment was minimized by the moderator on the site
Extremely helpfull! After editing it for my sheet i have #VALUE! for some of the unique values.
I did a countif to see if it could be that there are too many names to concatenate. The two unique values that have the #VALUE! error have 13635 and 19810 results. Is there a way to overcome this?
This comment was minimized by the moderator on the site
How can I ignore blank cells? mine currently displays this:

";;;;;;;;;"

I'd like for the 1st, 3rd and last 3 semi colons not to there/show. TIA
This comment was minimized by the moderator on the site
Hello, Chantelle
When concatenating the cell values ignoring the blank cells, please apply the below User Defined Function:

Function ConcatenateIf(CriteriaRange As Range, Condition As Variant, ConcatenateRange As Range, Optional Separator As String = ",") As Variant
Dim xResult As String
On Error Resume Next
If CriteriaRange.Count <> ConcatenateRange.Count Then
ConcatenateIf = CVErr(xlErrRef)
Exit Function
End If
For i = 1 To CriteriaRange.Count
If CriteriaRange.Cells(i).Value = Condition Then
If ConcatenateRange.Cells(i).Value <> "" Then
xResult = xResult & Separator & ConcatenateRange.Cells(i).Value
End If
End If
Next i
If xResult <> "" Then
xResult = VBA.Mid(xResult, VBA.Len(Separator) + 1)
End If
ConcatenateIf = xResult
Exit Function
End Function

Please try it, hope it can help you!
This comment was minimized by the moderator on the site
thank you very much! This was so simple and helped a lot!!
This comment was minimized by the moderator on the site
Is it possible to replace the comma splitter with a line break, i.e. char(10)? Many thanks.
This comment was minimized by the moderator on the site
Hello, David,

To combine the cells with line break, the following User Defined Function may help you.

Function ConcatenateIf_LineBreak(CriteriaRange As Range, Condition As Variant, ConcatenateRange As Range, Optional Separator As String = ",") As Variant
Dim xResult As String
On Error Resume Next
If CriteriaRange.Count <> ConcatenateRange.Count Then
ConcatenateIf = CVErr(xlErrRef)
Exit Function
End If
For I = 1 To CriteriaRange.Count
If CriteriaRange.Cells(I).Value = Condition Then
xResult = xResult & vbCrLf & ConcatenateRange.Cells(I).Value
End If
Next I
If xResult <> "" Then
xResult = VBA.Mid(xResult, VBA.Len(Separator) + 1)
End If
ConcatenateIf_LineBreak = xResult
Exit Function
End Function

After pasting this code, then apply this formula: =ConcatenateIf_LineBreak(A2:A13,F2,B2:B13,",").

After getting the results with this formula, you should click the Wrap Text to get the correct results you need.
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