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

or

Sut i wylio i ddychwelyd gwerthoedd lluosog mewn un cell yn Excel?

Fel rheol, yn Excel, pan fyddwch chi'n defnyddio'r swyddogaeth VLOOKUP, os oes sawl gwerth i gyd-fynd â'r meini prawf, gallwch chi gael yr un cyntaf. Ond, weithiau, rydych chi am ddychwelyd yr holl werthoedd cyfatebol sy'n cwrdd â'r meini prawf i mewn i un gell fel y dangosir y screenshot canlynol, sut allech chi ei ddatrys?

Vlookup i ddychwelyd gwerthoedd lluosog i mewn i un gell â swyddogaeth TEXTJOIN (Excel 2019 ac Office 365)

Vlookup i ddychwelyd gwerthoedd lluosog i mewn i un gell gyda Swyddogaeth Diffiniedig Defnyddiwr

Vlookup i ddychwelyd gwerthoedd lluosog i mewn i un gell gyda nodwedd ddefnyddiol


Vlookup i ddychwelyd gwerthoedd lluosog i mewn i un gell â swyddogaeth TEXTJOIN (Excel 2019 ac Office 365)

Os oes gennych y fersiwn uwch o'r Excel fel Excel 2019 ac Office 365, mae swyddogaeth newydd - TEXTJOIN, gyda'r swyddogaeth bwerus hon, gallwch chi edrych yn gyflym a dychwelyd yr holl werthoedd paru i mewn i un cell.

Vlookup i ddychwelyd yr holl werthoedd paru yn un gell

Defnyddiwch y fformiwla isod mewn cell wag lle rydych chi am roi'r canlyniad, yna pwyswch Ctrl + Shift + Enter allweddi gyda'i gilydd i gael y canlyniad cyntaf, ac yna llusgwch y ddolen llenwi i lawr i'r gell rydych chi am ddefnyddio'r fformiwla hon, a byddwch chi'n cael yr holl werthoedd cyfatebol fel y dangosir isod y screenshot:

=TEXTJOIN(",",TRUE,IF($A$2:$A$11=E2,$C$2:$C$11,""))

Nodyn: Yn y fformiwla uchod, A2: A11 yw'r ystod edrych yn cynnwys y data edrych, E2 yw'r gwerth edrych, C2: C11 yw'r ystod ddata rydych chi am ddychwelyd y gwerthoedd paru ohoni, ","yw'r gwahanydd i wahanu'r cofnodion lluosog.

Vlookup i ddychwelyd yr holl werthoedd paru heb ddyblygu i mewn i un gell

Os ydych chi am ddychwelyd yr holl werthoedd paru yn seiliedig ar y data edrych heb ddyblygu, gall y fformiwla isod eich helpu chi.

Copïwch a gludwch y fformiwla ganlynol i mewn i gell wag, yna pwyswch Ctrl + Shift + Enter allweddi gyda'i gilydd i gael y canlyniad cyntaf, ac yna copïwch y fformiwla hon i lenwi celloedd eraill, a byddwch yn cael yr holl werthoedd cyfatebol heb y rhai dulpicate fel y dangosir isod y screenshot:

=TEXTJOIN(",", TRUE, IF(IFERROR(MATCH($C$2:$C$11, IF(E2=$A$2:$A$11, $C$2:$C$11, ""), 0),"")=MATCH(ROW($C$2:$C$11), ROW($C$2:$C$11)), $C$2:$C$11, ""))

Nodyn: Yn y fformiwla uchod, A2: A11 yw'r ystod edrych yn cynnwys y data edrych, E2 yw'r gwerth edrych, C2: C11 yw'r ystod ddata rydych chi am ddychwelyd y gwerthoedd paru ohoni, ","yw'r gwahanydd i wahanu'r cofnodion lluosog.

Vlookup i ddychwelyd gwerthoedd lluosog i mewn i un gell gyda Swyddogaeth Diffiniedig Defnyddiwr

Dim ond ar gyfer Excel 2019 ac Office 365 y mae'r swyddogaeth TEXTJOIN uchod ar gael, os oes gennych fersiynau Excel is eraill, dylech ddefnyddio rhai codau ar gyfer gorffen y dasg hon.

Vlookup i ddychwelyd yr holl werthoedd paru yn un gell

1. Daliwch i lawr y ALT + F11 allweddi, ac mae'n agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

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

Cod VBA: Vlookup i ddychwelyd gwerthoedd lluosog i mewn i un gell

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

3. Yna arbedwch a chau'r cod hwn, ewch yn ôl i'r daflen waith, a nodi'r fformiwla hon: =CONCATENATEIF($A$2:$A$11, E2, $C$2:$C$11, ", ") i mewn i gell wag benodol lle rydych chi am osod y canlyniad, yna llusgwch y ddolen llenwi i lawr i gael yr holl werthoedd cyfatebol mewn un cell rydych chi ei eisiau, gweler y screenshot:

Nodyn: Yn y fformiwla uchod, A2: A11 yw'r ystod edrych yn cynnwys y data edrych, E2 yw'r gwerth edrych, C2: C11 yw'r ystod ddata rydych chi am ddychwelyd y gwerthoedd paru ohoni, ","yw'r gwahanydd i wahanu'r cofnodion lluosog.

Vlookup i ddychwelyd yr holl werthoedd paru heb ddyblygu i mewn i un gell

Er mwyn anwybyddu'r dyblygu yn y gwerthoedd paru a ddychwelwyd, gwnewch y cod isod.

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

Cod VBA: Vlookup a dychwelyd nifer o werthoedd cyfatebol unigryw i mewn i un gell

Function MultipleLookupNoRept(Lookupvalue As String, LookupRange As Range, ColumnNumber As Integer)
'Updateby Extendoffice
    Dim xDic As New Dictionary
    Dim xRows As Long
    Dim xStr As String
    Dim i As Long
    On Error Resume Next
    xRows = LookupRange.Rows.Count
    For i = 1 To xRows
        If LookupRange.Columns(1).Cells(i).Value = Lookupvalue Then
            xDic.Add LookupRange.Columns(ColumnNumber).Cells(i).Value, ""
        End If
    Next
    xStr = ""
    MultipleLookupNoRept = xStr
    If xDic.Count > 0 Then
        For i = 0 To xDic.Count - 1
            xStr = xStr & xDic.Keys(i) & ","
        Next
        MultipleLookupNoRept = Left(xStr, Len(xStr) - 1)
    End If
End Function

3. Ar ôl mewnosod y cod, yna cliciwch offer > cyfeiriadau yn yr agored Microsoft Visual Basic ar gyfer Ceisiadau ffenestr, ac yna, yn y popped allan Cyfeiriadau - VBAProject blwch deialog, gwirio Microsoft Scripting Runtime opsiwn yn y Cyfeiriadau sydd ar Gael blwch rhestr, gweler sgrinluniau:

4. Yna cliciwch OK i gau'r blwch deialog, cadw a chau'r ffenestr god, dychwelyd i'r daflen waith, a nodi'r fformiwla hon: =MultipleLookupNoRept(E2,$A$2:$C$11,3) into a blank cell where you want to output the result, and then drag the fill hanlde down to get all matching values, see screenshot:

Nodyn: Yn y fformiwla uchod, A2: C11 yw'r ystod ddata rydych chi am ei defnyddio, E2 yw'r gwerth edrych, y rhif 3 yw rhif y golofn sy'n cynnwys y gwerthoedd a ddychwelwyd.

Vlookup i ddychwelyd gwerthoedd lluosog i mewn i un gell gyda nodwedd ddefnyddiol

 Os oes gennych ein Kutools ar gyfer Excel, Gyda'i Rhesi Cyfuno Uwch nodwedd, gallwch chi uno neu gyfuno'r rhesi yn gyflym yn seiliedig ar yr un gwerth a gwneud rhai cyfrifiadau ag sydd eu hangen arnoch chi.

Nodyn:I gymhwyso hyn Rhesi Cyfuno Uwch, yn gyntaf, dylech lawrlwytho'r Kutools ar gyfer Excel, ac yna cymhwyswch y nodwedd yn gyflym ac yn hawdd.

Ar ôl gosod Kutools ar gyfer Excel, gwnewch fel a ganlyn:

1. Dewiswch yr ystod ddata rydych chi am gyfuno data un golofn yn seiliedig ar golofn arall.

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

3. Yn y popped allan Rhesi Cyfuno Uwch blwch deialog:

  • Cliciwch enw'r golofn allweddol i'w chyfuno yn seiliedig ar, ac yna cliciwch Allwedd Cynradd
  • Yna cliciwch colofn arall yr ydych am gyfuno ei data yn seiliedig ar y golofn allweddol, a chlicio Cyfunwch i ddewis un gwahanydd ar gyfer gwahanu'r data cyfun.

4. Yna cliciwch OK botwm, a byddwch yn cael y canlyniadau canlynol:

Dadlwythwch a threial am ddim Kutools ar gyfer Excel Now!


Erthyglau mwy cymharol:

  • Swyddogaeth VLOOKUP Gyda Rhai Enghreifftiau Sylfaenol ac Uwch
  • Yn Excel, mae swyddogaeth VLOOKUP yn swyddogaeth bwerus i'r rhan fwyaf o ddefnyddwyr Excel, a ddefnyddir i chwilio am werth yn y chwith mwyaf o'r ystod ddata, a dychwelyd gwerth paru yn yr un rhes o golofn a nodwyd gennych. Mae'r tiwtorial hwn yn siarad am sut i ddefnyddio swyddogaeth VLOOKUP gyda rhai enghreifftiau sylfaenol ac uwch yn Excel.
  • Dychwelwch werthoedd paru lluosog yn seiliedig ar un neu fwy o feini prawf
  • Fel rheol, mae'n hawdd i'r mwyafrif ohonom edrych ar werth penodol a dychwelyd yr eitem baru trwy ddefnyddio'r swyddogaeth VLOOKUP. Ond, a ydych erioed wedi ceisio dychwelyd gwerthoedd paru lluosog yn seiliedig ar un neu fwy o feini prawf? Yn yr erthygl hon, byddaf yn cyflwyno rhai fformiwlâu ar gyfer datrys y dasg gymhleth hon yn Excel.
  • Vlookup A Dychwelyd Gwerthoedd Lluosog yn Fertigol
  • Fel rheol, gallwch ddefnyddio'r swyddogaeth Vlookup i gael y gwerth cyfatebol cyntaf, ond, weithiau, rydych chi am ddychwelyd yr holl gofnodion paru yn seiliedig ar faen prawf penodol. Yr erthygl hon, byddaf yn siarad am sut i wylio a dychwelyd yr holl werthoedd paru yn fertigol, yn llorweddol neu i mewn i un gell.
  • Vlookup A Dychwelyd Gwerthoedd Lluosog O'r Rhestr Gostwng
  • Yn Excel, sut allech chi wylio a dychwelyd sawl gwerth cyfatebol o gwymplen, sy'n golygu pan fyddwch chi'n dewis un eitem o'r gwymplen, mae ei holl werthoedd cymharol yn cael eu harddangos ar unwaith. Yr erthygl hon, byddaf yn cyflwyno'r datrysiad gam wrth gam.

Yr Offer Cynhyrchedd Swyddfa Gorau

Mae Kutools for Excel yn Datrys y rhan fwyaf o'ch Problemau, ac yn Cynyddu Eich Cynhyrchedd 80%

  • Ailddefnyddio: Mewnosod yn gyflym fformwlâu cymhleth, siartiau ac unrhyw beth rydych chi wedi'i ddefnyddio o'r blaen; Amgryptio Celloedd gyda chyfrinair; Creu Rhestr Bostio ac anfon e-byst ...
  • Bar Fformiwla Gwych (golygu llinellau lluosog o destun a fformiwla yn hawdd); Cynllun Darllen (darllen a golygu nifer fawr o gelloedd yn hawdd); Gludo i'r Ystod Hidlo...
  • Uno Celloedd / Rhesi / Colofnau heb golli Data; Cynnwys Celloedd Hollt; Cyfuno Rhesi / Colofnau Dyblyg... Atal Celloedd Dyblyg; Cymharwch y Meysydd...
  • Dewiswch Dyblyg neu Unigryw Rhesi; Dewiswch Blank Rows (mae pob cell yn wag); Darganfyddiad Gwych a Darganfyddiad Niwlog mewn Llawer o Lyfrau Gwaith; Dewis ar Hap ...
  • Copi Union Celloedd Lluosog heb newid cyfeirnod fformiwla; Auto Creu Cyfeiriadau i Daflenni Lluosog; Mewnosod Bwledi, Blychau Gwirio a mwy ...
  • Testun Detholiad, Ychwanegu Testun, Tynnu yn ôl Swydd, Tynnwch y Gofod; Creu ac Argraffu Subtotals Paging; Trosi rhwng Cynnwys a Sylwadau Celloedd...
  • Hidlo Super (arbed a chymhwyso cynlluniau hidlo i ddalenni eraill); Trefnu Uwch yn ôl mis / wythnos / dydd, amlder a mwy; Hidlo Arbennig gan feiddgar, italig ...
  • Cyfuno Llyfrau Gwaith a Thaflenni Gwaith; Uno Tablau yn seiliedig ar golofnau allweddol; Rhannwch Ddata yn Daflenni Lluosog; Trosi Swp xls, xlsx a PDF...
  • Mwy na 300 o nodweddion pwerus. Yn cefnogi Swyddfa / Excel 2007-2019 a 365. Yn cefnogi pob iaith. Defnydd hawdd yn eich menter neu sefydliad. Nodweddion llawn treial am ddim 30 diwrnod. Gwarant arian yn ôl 60 diwrnod.
tab kte 201905

Mae Tab Office yn Dod â rhyngwyneb Tabbed i'r Swyddfa, a 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!
gwaelod officetab
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.
    Salman · 8 months ago
    Thank you so much for the code. Is there a way I can use the code to look up multiple values from multiple sheets? I tried to combine your function with IFERROR function but it doesn't seem to work.
  • To post as a guest, your comment is unpublished.
    Joe · 10 months ago
    Can this be modified to place the sum of those values? Instead of (400 400 400 400 400 400), can it sum them to show (2400)?
  • To post as a guest, your comment is unpublished.
    Yudhi · 11 months ago
    How with HLookUp function?

  • To post as a guest, your comment is unpublished.
    Chris F · 1 years ago
    thanks for the code. I have modified it to allow you to optionally specify your own separator, Default is " ", if you specify the separator as"#cr" it will insert a CR/LF so the values will be on a separate line in the cell. It only applies the separator if there are multiple values

    Function MYVLOOKUP(pValue As String, pWorkRng As Range, pIndex As Long, Optional ByVal pSep As Variant)
    ' ### Returns multiple values from a table into 1 cell ###
    ' pValue is the key value to lookup
    ' WorkRng is the Table you want to look up
    ' pIndex is the column # for the values to be returned from the pWorkRng
    ' pSep (optional) is the separator to be used. if omitted then default is a space (it doesn't apply the separator for the 1st entry)
    ' if the separtor = "#cr" it will separate the values on different line in the cell
    Dim rng As Range
    Dim sSep As String
    Dim xResult As String
    Dim Item1 As Boolean
    Item1 = True

    If IsMissing(pSep) = True Then
    sSep = vbCr
    Else
    If pSep = "#cr" Then
    sSep = vbCrLf
    Else
    sSep = pSep
    End If
    End If

    xResult = ""
    For Each rng In pWorkRng
    If rng = pValue Then
    If Item1 Then
    xResult = xResult & rng.Offset(0, pIndex - 1)
    Item1 = False
    Else
    xResult = xResult & sSep & rng.Offset(0, pIndex - 1)
    End If
    End If
    Next
    MYVLOOKUP = xResult
    End Function


    • To post as a guest, your comment is unpublished.
      Brad · 11 months ago
      Thank you for this, the line breaks are what i needed to top this formula off! Question, is there a way to modify the code so that two values are compared? For example, similar to what we see with index and match, can i look for Product and Quantity columns, and based on those parameters it outputs results from the Region Column?
  • To post as a guest, your comment is unpublished.
    James · 1 years ago
    Thanks a lot for this code, it is very helpful. Does anyone know away to sum the values in the cell to just have at total of them.
    Cheers
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello, James, to sum values based on the corresponding items, the following article may help you, please chek it:
      https://www.extendoffice.com/documents/excel/1268-excel-combine-duplicate-rows-and-sum.html
  • To post as a guest, your comment is unpublished.
    Sasi maddy · 1 years ago
    I have a server, it has connected with multiple applications. I want to compare compare two column and get the related applications details for that server.

    What is the command for that.
  • To post as a guest, your comment is unpublished.
    Matt K · 1 years ago
    Put comma between each response: =SUBSTITUTE(TRIM(myvlookup(E6,$A$2:$C$15,2))," ",", ")
  • To post as a guest, your comment is unpublished.
    Martin · 1 years ago
    Unfortunately it does not work for me =myvlookup(E6,$A$2:$C$15,2) as the result is #NAME?
    • To post as a guest, your comment is unpublished.
      Mr. Summey · 10 months ago
      Did you get this figured out? I am having the same problem.
      • To post as a guest, your comment is unpublished.
        Zahsan · 9 months ago
        having the same problem :(
  • To post as a guest, your comment is unpublished.
    Steven · 1 years ago
    Thank you. I just modified so that it will replace the comma at the start and replace the last comma with "And".

    (Working with states)

    Function MYVLOOKUP(pValue As String, pWorkRng As Range, pIndex As Long)

    Dim rng As Range
    Dim xResult, States As String
    Dim Pos As Long
    xResult = ""
    For Each rng In pWorkRng
    If rng = pValue Then
    xResult = xResult & ", " & rng.Offset(0, pIndex - 1)
    End If
    Next
    States = Right(xResult, Len(xResult) - 2)
    Pos = InStrRev(States, ",")

    If Pos > 1 Then
    States = Mid(States, 1, Pos - 1) & Replace(States, ",", " AND", Pos)

    End If

    MYVLOOKUP = States
    End Function
  • To post as a guest, your comment is unpublished.
    Devinder Kaur · 2 years ago
    do we have the code to work it from last to first. like we have multiple values in columnB and we want them in row with column A remain same.
  • To post as a guest, your comment is unpublished.
    Pam · 2 years ago
    For some reason this macro is extremely slow for me, every time I click anywhere it takes about 5-10 minutes to calculate.
  • To post as a guest, your comment is unpublished.
    Alex · 2 years ago
    Tthat's what I wanted! Thank you very much XD
  • To post as a guest, your comment is unpublished.
    Tom T · 2 years ago
    This is amazing, thank you!
  • To post as a guest, your comment is unpublished.
    Mark · 2 years ago
    Great function, however chunking through 100,000 records proves a bit much for my poor laptop, will need to let it run overnight!
  • To post as a guest, your comment is unpublished.
    Will · 3 years ago
    Is there a way of amending the result so instead of showing 1000 1000 -1000 it would show for example 1,000/1,000/(1,000) ?
  • To post as a guest, your comment is unpublished.
    Kabilankumar · 4 years ago
    Great macro, useful.

    But need to know can it be modified to check 2 criteria & does anyone found anyway to make wildcards work on it.

    Any help?
  • To post as a guest, your comment is unpublished.
    Jay · 4 years ago
    No matter what I do, I always get #value! returned instead of a result. vlookup works just fine, so the data works. Already followed the process of enabling macros. I even combined everything into a single sheet. Any ideas??
  • To post as a guest, your comment is unpublished.
    Curtis · 4 years ago
    This worked perfectly, but it did take me some time to get the Function work properly within my 20 tab, 50k+ line spreadsheet.
    Now the BIG question is how to take that delimited string and then use each entry as an Index/Match (not married to Index/Match, but it seems faster) lookup value in another dataset, returning the SUM value of all returns into one cell. My scenario is that I have a Single Order that has multiple invoices. Your MYVLOOKUP Function works superbly to report back all of the invoices in one cell. What I want to do now is to take each concatenated return with the reported cell, spin through that array and total the amounts of payment of each invoice back into the formula cell.

    I appreciate any help that you can offer on this and thanks for the MYVLOOKUP Function!
  • To post as a guest, your comment is unpublished.
    Alex Chow · 4 years ago
    To get unique record, you may use below: (modified by refer other user code)


    Function MYVLOOKUP(pValue As String, pWorkRng As Range, pIndex As Long)
    'Update 20150310
    'Updated 6/9/16 Jay Coltrain
    'Dim rng As Range
    Dim xResult As String
    xResult = ""

    Dim Rows As Long, i As Long
    Rows = pWorkRng.Rows.Count

    For i = 1 To Rows
    If pWorkRng.Cells(i, 1).Value = pValue Then
    xResult = xResult & "," & pWorkRng.Cells(i, 1).Offset(0, pIndex - 1)
    End If
    Next i

    Dim varSection As Variant
    Dim sTemp As String
    Dim sDelimiter As String

    sDelimiter = ","

    For Each varSection In Split(xResult, sDelimiter)
    If InStr(1, sDelimiter & sTemp & sDelimiter, sDelimiter & varSection & sDelimiter, vbTextCompare) = 0 Then
    sTemp = sTemp & sDelimiter & varSection
    End If
    Next varSection


    MYVLOOKUP = Mid(sTemp, Len(sDelimiter) + 1)
    End Function
  • To post as a guest, your comment is unpublished.
    Spyros Tzortzis · 4 years ago
    Heads-up. I figured out how to get any separator in that output. Its rudimentary. But I figured it out.

    xResult = xResult & "///" & rng.Offset(0, pIndex - 1)

    The last and most wished for thing though is enabling it to work with wildcards in the search criteria. Thank you again for this beautiful and brilliant solution. Extremely helpful. Now just want to get get the macro to run and be installed in my excel perminantly no matter what I'm doing so I can use it when I need to.

    And wildcards!

    Thank you so much.

    Wildcards are all that are left to do.
  • To post as a guest, your comment is unpublished.
    Spyros Tzortzis · 4 years ago
    Hi,

    It works well. What I would like to do is adapt the code to seperate thee value results with "///" or any other marker (for technical reasons, I don't want just a single character seperator).

    Also, I noticed that this formula doesnt work with a wild card. I know i am asking too much, but it doesnt as vlookup can work when i search for =myvlookup("*"&E6&"*",$A$2:$C$15,2) which it would do/could do.

    Any assistance?
  • To post as a guest, your comment is unpublished.
    Ajay · 4 years ago
    Return nothing! after applying MYLOOKUP giving no result but blank.
  • To post as a guest, your comment is unpublished.
    Rob · 4 years ago
    Notify me of follow-up comments
  • To post as a guest, your comment is unpublished.
    cory · 4 years ago
    This works great, but I still need help with the command function to remove duplicates from the results.
  • To post as a guest, your comment is unpublished.
    cory · 4 years ago
    This works great, but I need help with the command to remove duplicates from the results. Seriously though, Great work.
  • To post as a guest, your comment is unpublished.
    Jay · 5 years ago
    This is exactly what I was looking for and did not think of just making my own UDF. However it will not function exactly like VLOOKUP. If the string you are looking for is not only in the first column then it could give you data outside the original range passed.

    Name Number Other name Column not in range passed
    Jay 1 Jay 1
    Jay 2 Jay 2
    Chris 3 Chris 3
    Jorge 4 Jorge 4
    Jay 5 Jay 5
    Jorge 6 Jorge 6

    If the above table were cells A1:D7 if you passed only A1:C7 your "MYVLOOKUP" function returns 1 1 2 2 5 5 when you would expect it to return 1 2 5.

    The changes below fix the issue:

    Function MYVLOOKUP(pValue As String, pWorkRng As Range, pIndex As Long)
    'Update 20150310
    'Updated 6/9/16 Jay Coltrain
    'Dim rng As Range
    Dim xResult As String
    xResult = ""

    Dim Rows As Long, i As Long
    Rows = pWorkRng.Rows.Count

    For i = 1 To Rows
    If pWorkRng.Cells(i, 1).Value = pValue Then
    xResult = xResult & " " & pWorkRng.Cells(i, 1).Offset(0, pIndex - 1)
    End If
    Next i

    'For Each rng In pWorkRng
    ' If rng = pValue Then
    ' xResult = xResult & " " & rng.Offset(0, pIndex - 1)
    ' End If
    'Next
    MYVLOOKUP = xResult
    End Function
  • To post as a guest, your comment is unpublished.
    Ari · 5 years ago
    Thank you for the VBA-code. I got exactly what I want!

    I modified only the code " rng.Offset(0, pIndex - 1) " to " rng.Offset(0, pIndex - 2) " . So is MYVLOOKUP able to search from Right to Left.
  • To post as a guest, your comment is unpublished.
    Ankit Jain · 5 years ago
    Hi,
    i am really impressed with the work and its so easy to create one to use this function. however i need further support.

    My ? is that how can i select a number from a cell with multiple cell in my vlookup array. i.e.

    If cell A1 = 100, A2 = 350, A3 = 69

    C1 = 100; 1222; 12133
    C2 = 69; 222
    D1 = Apple
    D2 = banana

    So how can select 100 from my table array column C to derive correspondent D1 = apple

    Please note that i have 7 digit numbers in my lookup value and table array which is separated by a ";". I would really appreciate if you can solve this and help me in saving a lot time.
  • To post as a guest, your comment is unpublished.
    Ajay · 5 years ago
    Awesome work.. Got exactly what I want !!! Love it !!
  • To post as a guest, your comment is unpublished.
    Colleen · 5 years ago
    Thank you for sharing the above code. I've been using this for several months now but today it doesn't seem to work. I'm getting blank cells instead of the usual error when there is data to be returned. Any thoughts?
  • To post as a guest, your comment is unpublished.
    David V · 5 years ago
    Thanks for the VBA code above. Can you tell me how to make the results enter onto a new line in the cell, ie like Alt-Enter
    300
    400
    1000
    1300
  • To post as a guest, your comment is unpublished.
    David Atwell · 5 years ago
    How would I adjust this formula to separate each returned value but ", " as well as only return unique values?
    • To post as a guest, your comment is unpublished.
      Michael · 1 years ago
      Thanks for the code!!

      As for wildcards, a way around is using INSTR

      You can replace the [ If rng = pValue Then ] with [ InStr(1, rng.Value, pValue) Then ] and if you don't want it to be case sensitive then use [ InStr(1, rng.Value, pValue, vbTextCompare) Then ]