Skip i'r prif gynnwys

Sut i ddychwelyd gwerthoedd edrych lluosog mewn un gell sydd wedi'i gwahanu gan goma?

Yn Excel, gallwn gymhwyso swyddogaeth VLOOKUP i ddychwelyd y gwerth cyfatebol cyntaf o gelloedd bwrdd, ond, weithiau, mae angen i ni dynnu'r holl werthoedd paru ac yna eu gwahanu gan amffinydd penodol, fel coma, dash, ac ati ... i mewn i un cell fel y dangosir y screenshot canlynol. Sut y gallem gael a dychwelyd gwerthoedd edrych lluosog mewn un gell sydd wedi'i gwahanu gan goma yn Excel?

doc dychwelyd coma gwerthoedd lluosog wedi'u gwahanu 1

Dychwelwch werthoedd edrych lluosog mewn un gell sydd wedi'i gwahanu â choma gyda Swyddogaeth wedi'i Diffinio gan Ddefnyddiwr

Dychwelwch werthoedd chwilio lluosog mewn un gell wedi'i gwahanu gan goma gyda Kutools ar gyfer Excel


Dychwelwch werthoedd edrych lluosog mewn un gell sydd wedi'i gwahanu â choma gyda Swyddogaeth wedi'i Diffinio gan Ddefnyddiwr

Fel rheol, nid oes unrhyw ffordd uniongyrchol inni dynnu a dychwelyd y gwerthoedd paru lluosog a'u gwahanu gan goma i mewn i un gell, yma, gallwch greu Swyddogaeth Diffiniedig Defnyddiwr i ddatrys y swydd hon, gwnewch fel a ganlyn:

1. Daliwch i lawr 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 Modiwlau Ffenestr.

Cod VBA: Dychwelwch werthoedd edrych lluosog i mewn i un gell sydd wedi'i gwahanu gan goma

Function SingleCellExtract(LookupValue As String, LookupRange As Range, ColumnNumber As Integer, Char As String)
'Updateby Extendoffice
    Dim I As Long
    Dim xRet As String
    For I = 1 To LookupRange.Columns(1).Cells.Count
        If LookupRange.Cells(I, 1) = LookupValue Then
            If xRet = "" Then
                xRet = LookupRange.Cells(I, ColumnNumber) & Char
            Else
                xRet = xRet & "" & LookupRange.Cells(I, ColumnNumber) & Char
            End If
        End If
    Next
    SingleCellExtract = Left(xRet, Len(xRet) - 1)
End Function

3. Yna cadwch y cod hwn a chau ffenestr y Modiwl, ewch yn ôl i'ch taflen waith, a nodi'r fformiwla hon: = SingleCellExtract (D2, A2: B15,2, ",") i mewn i gell wag rydych chi am ddychwelyd y canlyniad. Ac yna pwyswch Rhowch allwedd i gael y canlyniad, gweler y screenshot:

doc dychwelyd coma gwerthoedd lluosog wedi'u gwahanu 2

Nodyn: Yn y fformiwla uchod:

D2: yn nodi'r gwerthoedd celloedd yr ydych am edrych arnynt;

A2: B15: yw'r ystod ddata rydych chi am nôl y data;

2: y rhif 2 yw'r rhif colofn y dylid dychwelyd y gwerth cyfatebol;

,: y coma yw'r gwahanydd rydych chi am wahanu'r gwerthoedd lluosog.

Gallwch eu newid i'ch angen.


Dychwelwch werthoedd chwilio lluosog mewn un gell wedi'i gwahanu gan goma gyda Kutools ar gyfer Excel

Os oes gennych Kutools ar gyfer Excel, ni fydd y dasg hon yn broblem mwyach. Mae'r Rhesi Cyfuno Uwch gall cyfleustodau eich helpu i gyfuno'r holl werthoedd cymharol yn seiliedig ar golofn.

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 a ganlyn:

1. Dewiswch yr ystod ddata rydych chi am gyfuno'r holl werthoedd paru yn seiliedig ar 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 enw'r golofn rydych chi am ei chyfuno yn seiliedig, ac yna cliciwch Allwedd Cynradd botwm, gweler y screenshot:

doc dychwelyd coma gwerthoedd lluosog wedi'u gwahanu 4

4. Yna cliciwch enw colofn arall rydych chi am gyfuno eu gwerthoedd cyfatebol, a chlicio Cyfunwch i ddewis un gwahanydd i wahanu'r gwerthoedd cyfun, gweler y screenshot:

doc dychwelyd coma gwerthoedd lluosog wedi'u gwahanu 5

5. Yna cliciwch OK botwm, mae'r holl gelloedd cyfatebol sydd â'r un gwerth wedi'u cyfuno i mewn i un gell sydd wedi'u gwahanu â'r coma, gweler sgrinluniau:

doc dychwelyd coma gwerthoedd lluosog wedi'u gwahanu 6 2 doc dychwelyd coma gwerthoedd lluosog wedi'u gwahanu 7

Cliciwch i wybod mwy o fanylion am y cyfleustodau Advanced Combine Rows hwn ...

Dadlwythwch a threial am ddim Kutools ar gyfer Excel Nawr !


Demo: Dychwelwch werthoedd chwilio lluosog mewn un gell wedi'i gwahanu gan goma gyda Kutools ar gyfer Excel

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 (19)
Rated 5 out of 5 · 2 ratings
This comment was minimized by the moderator on the site
Como faço para ajustar a função do "MultipleValues" para ignorar células vazias?

Pois no meu caso tenho algumas células em branco e quando faço o merge, fico com algumas vírgulas repetidas.

Ex.: (001,002,,,,003).

Obrigado!
This comment was minimized by the moderator on the site
Hello, Bruno,
To ignore the blank cells when combine, pleae apply the following code:

Function SingleCellExtract(LookupValue As String, LookupRange As Range, ColumnNumber As Integer, Char As String) As String
    Dim I As Long
    Dim xRet As String
    For I = 1 To LookupRange.Columns(1).Cells.Count
        If LookupRange.Cells(I, 1) = LookupValue Then
            ' Check if the cell in the specified column is not empty before appending
            If Not IsEmpty(LookupRange.Cells(I, ColumnNumber)) Then
                If xRet = "" Then
                    xRet = LookupRange.Cells(I, ColumnNumber) & Char
                Else
                    xRet = xRet & LookupRange.Cells(I, ColumnNumber) & Char
                End If
            End If
        End If
    Next
    If Len(xRet) > 0 Then
        SingleCellExtract = Left(xRet, Len(xRet) - 1)
    Else
        SingleCellExtract = ""
    End If
End Function


Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Hello skyyang,

Yes, it works!

Thank you!
This comment was minimized by the moderator on the site
No soy programador pero necesito ayuda para que la función de abajo en lugar de devolverme esto

S-01-08-0017->Micro Post 1R, Black, Stainless Steel -End,->4;S-01-08-0057->Micro Post 2R, Black, Stainless Steel -End,->2

me devuelva los valores en líneas diferentes.
S-01-08-0017->Micro Post 1R, Black, Stainless Steel -End,->4
S-01-08-0057->Micro Post 2R, Black, Stainless Steel -End,->2

La función es:
Function SingleCellExtract(LookupValue As String, LookupRange As Range, ColumnNumber As Integer, Char As String)
'Updateby Extendoffice
Dim I As Long
Dim xRet As String
For I = 1 To LookupRange.Columns(1).Cells.Count
If LookupRange.Cells(I, 1) = LookupValue Then
If xRet = "" Then
xRet = LookupRange.Cells(I, ColumnNumber) & Char
Else
xRet = xRet & "" & LookupRange.Cells(I, ColumnNumber) & Char
End If
End If
Next
SingleCellExtract = Left(xRet, Len(xRet) - 1)
End Function
This comment was minimized by the moderator on the site
Hello, Yery,
Did you mean to split a cell into multiple rows based on the semicolon character?
If so, the following VBA code can help you:
Sub SplitAll()
    Dim xRg As Range
    Dim xRg1 As Range
    Dim xCell As Range
    Dim I As Long
    Dim xAddress As String
    Dim xUpdate As Boolean
    Dim xRet As Variant
    On Error Resume Next
    xAddress = Application.ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select a range", "Kutools for Excel", xAddress, , , , , 8)
    Set xRg = Application.Intersect(xRg, xRg.Worksheet.UsedRange)
    If xRg Is Nothing Then Exit Sub
        If xRg.Columns.Count > 1 Then
            MsgBox "You can't select multiple columns", , "Kutools for Excel"
            Exit Sub
            End If
            Set xRg1 = Application.InputBox("Split to (single cell):", "Kutools for Excel", , , , , , 8)
            Set xRg1 = xRg1.Range("A1")
            If xRg1 Is Nothing Then Exit Sub
                xUpdate = Application.ScreenUpdating
                Application.ScreenUpdating = False
                For Each xCell In xRg
                    xRet = Split(xCell.Value, ";")
                    xRg1.Worksheet.Range(xRg1.Offset(I, 0), xRg1.Offset(I + UBound(xRet, 1), 0)) = Application.WorksheetFunction.Transpose(xRet)
                    I = I + UBound(xRet, 1) + 1
                Next
                Application.ScreenUpdating = xUpdate
            End Sub

Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Hi,

I want exact validation code for multiple values separated by comma and space for each value.

Example:
Lucy, Tom, Nicol, Akash, Apple

Please replay if you have any suggestions.
Rated 4.5 out of 5
This comment was minimized by the moderator on the site
Hello, Manikanta
To separate the multiple values by a comma and space, you just need to add a space behind the comma, change the formula as this: =SingleCellExtract(D2,A2:B15,2,", ").
Please try, hope it can help you!
This comment was minimized by the moderator on the site
Hi Skyyang,

Thanks for your replay!

I tried already same way but in the cell value last one extra comma (,) coming below is the example.

Lucy, Tom, Nicol, Akash, Apple,

This will not work for Json file, so I want values separated by comma and space like below.

Lucy, Tom, Nicol, Akash, Apple

Thank you!
This comment was minimized by the moderator on the site
Hello, Manikanta
In this case, you can apply the below User Defined Function:

Function MultipleValues(work_range As Range, criteria As Variant, merge_range As Range, Optional Separator As String = ",") As Variant
Dim outcome As String
On Error Resume Next
If work_range.Count <> merge_range.Count Then
MultipleValues = CVErr(xlErrRef)
Exit Function
End If
For i = 1 To work_range.Count
If work_range.Cells(i).Value = criteria Then
outcome = outcome & Separator & merge_range.Cells(i).Value
End If
Next i
If outcome <> "" Then
outcome = VBA.Mid(outcome, VBA.Len(Separator) + 1)
End If
MultipleValues = outcome
Exit Function
End Function


After pasting the code, please use this formula: =MultipleValues($A$2:$A$15,D2,$B$2:$B$15,", ")

Please try, hope this can help you!
If you still have any other problem, please comment here.
https://www.extendoffice.com/images/stories/comments/comment-skyyang/doc-return-multiple-matching-1.png
This comment was minimized by the moderator on the site
Hi Skyyang,

This is working now, Thank you for your quick response.

It's very use full to me once again Thank you for your help.

Regards,
Manikanta.
Rated 5 out of 5
This comment was minimized by the moderator on the site
Good Morning,

the VBA code worked perfectly with my worksheet, pretty clear and simple, however, I was trying to find a way to tell excel to only return the unique values. Would that be possible using this same code?
Rated 5 out of 5
This comment was minimized by the moderator on the site
When 2 Criteria Match then Return Multiple Lookup Values In One Comma Separated Cell
A2=B2 Then Result From Range by "SingleCellExtract" - Please.......
This comment was minimized by the moderator on the site
Error pops up if increase the array size
This comment was minimized by the moderator on the site
VB command breaks when the range is longer than 154 rows (ie :B154)....
This comment was minimized by the moderator on the site
thank you, firstly i managed to get this to work without the slow down in performance. I'm using values rather that text so my question is i want to bring back all those with less than say 19 points in a list. Can the single cell Extract work for that or does it have to be a specific value?
This comment was minimized by the moderator on the site
This simply does not work. I was unable to get it to work in my own application, so I copy/pasted the vba and the formula and it returned an error every time
This comment was minimized by the moderator on the site
This works but slows down my excel majorly! Any tips to help speed?
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