Namig: drugi jeziki so prevedeni v Google. Lahko obiščete English različico te povezave.
Vpiši se
x
or
x
x
Registracija
x

or

Kako preusmeriti in vrniti več vrednosti brez podvajanj v Excelu?

Včasih boste morda želeli vlookup in vrniti več ujemajočih vrednosti v eno celico hkrati. Ampak, če obstajajo ponavljajoče se vrednosti, ki so vnesene v vrnjene celice, kako lahko prezrete podvojene in ohranite edinstvene vrednosti, ko vračate vse ujemajoče vrednosti kot naslednji posnetek zaslona, ​​prikazan v Excelu?

doc vrne več edinstvenih vrednosti 1

Vlookup in vrnitev več ujemajočih se vrednosti brez podvajanj z uporabo uporabniško določenega funkcij


Vlookup in vrnitev več ujemajočih se vrednosti brez podvajanj z uporabo uporabniško določenega funkcij

Naslednja VBA koda vam lahko pomaga pri vračanju več ujemajočih vrednosti brez podvajanj, storite tako:

1. Drži dol Alt + F11 tipke za odpiranje Microsoft Visual Basic za aplikacije okno.

2. Kliknite Vstavi > Moduli, in prilepite naslednjo kodo v Moduli Okno.

VBA koda: Vlookup in vrne več enkratnih ujemajočih vrednosti:

Function MultipleLookupNoRept(Lookupvalue As String, LookupRange As Range, ColumnNumber As Integer)
    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. Ko vstavite kodo, kliknite Orodja > Reference v odprtem Microsoft Visual Basic za aplikacije okno, in nato, v popped out Reference - VBAProjekt pogovorno okno, preveri Microsoft Scripting Runtime možnost v Razpoložljive reference polje s seznamom, si oglejte sliko zaslona:

doc vrne več edinstvenih vrednosti 2

4. Nato kliknite OK zaprete pogovorno okno, shranite in zaprite okno kode, se vrnite na delovni list in vnesite to formulo: =MultipleLookupNoRept(E2,A2:C17,3) v prazno celico, kjer želite izpisati rezultat, pritisnite Vnesite ključ, da dobite pravilen rezultat, kot ga potrebujete. Prikaz slike:

doc vrne več edinstvenih vrednosti 3

Opombe: V zgornji formuli, E2 so merila, ki jih želite preusmeriti, A2: C17 je obseg podatkov, ki ga želite uporabiti, številko 3 številka stolpca, ki vsebuje vrnjene vrednosti.



Priporočena orodja za produktivnost za Excel

Kutools za Excel vam pomaga, da vedno končate delo pred časom in izstopite iz množice

  • Več kot zmogljive napredne funkcije 300, zasnovane za 1500 delovne scenarije, ki povečujejo produktivnost z 70%, vam dajejo več časa za skrb za družino in uživanje v življenju.
  • Ne potrebujete več pomnilniških formul in VBA kod, od zdaj naprej pa dajate svojim možganom počitek.
  • Postanite strokovnjak za Excel v minutah 3, zapletene in ponavljajoče se operacije lahko opravite v nekaj sekundah,
  • Vsak dan zmanjšajte število operacij tipkovnice in miške, zdaj se poslovite od poklicnih bolezni.
  • 110,000 visoko učinkovite ljudi in 300 + svetovno priznanih podjetij izbiro.
  • Brezplačna preizkusna različica 60 dneva. 60-dnevno jamstvo vračila denarja. 2 let brezplačne nadgradnje in podpore.

Prinaša kartično brskanje in urejanje za Microsoft Office, veliko močnejši od zavihkov brskalnika

  • Office Tab je namenjen za Word, Excel, PowerPoint in druge Office aplikacije: Založnik, Dostop, Visio in Projekt.
  • Odprite in ustvarite več dokumentov v novih zavihkih istega okna in ne v novih oknih.
  • Z 50% poveča vašo produktivnost in vsak dan zmanjša na stotine klikov z miško!
Say something here...
symbols left.
You are guest ( Sign Up? )
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.
    Rasike · 3 months ago
    Hi

    I wanted to create a list in a table from this instead of all results in one cell. So I have used a formula similar below (what you have suggested)

    =LOOKUP(2, 1/((COUNTIF($E$1:E1, $B$2:$B$12)=0)*($D$2=$A$2:$A$12)), $B$2:$B$12)

    However, this is taking a long time to process from a large set of data.
    Is there any alternative method to process this faster?
    Thanks again
    Rasike
  • To post as a guest, your comment is unpublished.
    Imre · 4 months ago
    xStr = xStr & xDic.Keys(I) & "," to be this: xStr = xStr & xDic.Keys(I) & ", "

    Is there a way to replace "," with in-cell ALT+ENTER, so that the results will be in the same cell but on different lines? Do I need to introduce additional VBA module for that and combine them?

    Also, this code is quite slow when looping over huge tables. Anyone knows any faster solutions?
    • To post as a guest, your comment is unpublished.
      skyyang · 4 months ago
      Hi, Imre,
      To separate the result values by Alt + Enter keys, please apply the following User Defined Function:

      Function MultipleLookupNoRept(Lookupvalue As String, LookupRange As Range, ColumnNumber As Integer)
      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) & Chr(10) + Chr(13)
      Next
      MultipleLookupNoRept = Left(xStr, Len(xStr) - 1)
      End If
      Debug.Print xStr
      End Function

      And then do with the above steps in this article, at last, after entering the formula, you should click Wrap Text under the Home tab.
  • To post as a guest, your comment is unpublished.
    Demetre · 10 months ago
    Is there a way to add a space in between the multiple values retrieved in the results without introducing a comma at the end of the list? For example your result above would show as: "Emily, James, Daisy, Gary" instead of like this: "Emily,James,Daisy,Gary"

    I tried to edit this portion of the VBA code: xStr = xStr & xDic.Keys(I) & "," to be this: xStr = xStr & xDic.Keys(I) & ", "

    That did add the space in between the values, but it also added a comma after the last value. "Emily, James, Daisy, Gary,"

    Is there a way to make it work with the space but without the extra comma after the last value?
    • To post as a guest, your comment is unpublished.
      skyyang · 10 months ago
      Hello, Demetre,
      Use the space to separate the values, you just need to change the vba code:
      from xStr = xStr & xDic.Keys(i) & "," to be this: xStr = xStr & xDic.Keys(i) & " "

      Please try it.
  • To post as a guest, your comment is unpublished.
    Tom · 11 months ago
    what if I wanted to create a list in a table from this instead of all results in one cell?
    • To post as a guest, your comment is unpublished.
      skyyang · 11 months ago
      Hello, Tom,
      If you want to extract the unique values in a list of cells instead of one cell, the following formula may help you:

      =LOOKUP(2, 1/((COUNTIF($E$1:E1, $B$2:$B$12)=0)*($D$2=$A$2:$A$12)), $B$2:$B$12)

      Please try it.
      • To post as a guest, your comment is unpublished.
        Rasike · 3 months ago
        Hi Skyyang,

        Thank you very much for this formula.
        This works for me. However, it is taking a long time to process from a large set of data.
        Can we modify this formula to work this bit faster?
        Thanks again
        Rasike