Preskoči na glavno vsebino

 Kako ustvariti spustni seznam, a prikazati različne vrednosti v Excelu?

V Excelovem delovnem listu lahko hitro ustvarimo spustni seznam s funkcijo preverjanja podatkov, vendar, ali ste že kdaj poskusili prikazati drugačno vrednost, ko kliknete spustni seznam? Na primer, v stolpcu A in stolpcu B imam naslednja dva podatka v stolpcu. Zdaj moram ustvariti spustni seznam z vrednostmi v stolpcu Ime, toda, ko na ustvarjenem spustnem seznamu izberem ime, ustrezen vrednost v stolpcu Število je prikazana, kot je prikazano na sliki spodaj. Ta članek bo predstavil podrobnosti za rešitev te naloge.

doc spustni meni različne vrednosti 1

Ustvari spustni seznam, vendar v celici spustnega seznama prikaži drugačno vrednost


Ustvari spustni seznam, vendar v celici spustnega seznama prikaži drugačno vrednost

Če želite dokončati to nalogo, sledite naslednjim korakom:

1. Na spustnem seznamu ustvarite ime obsega za vrednosti celic, ki jih želite uporabiti, v tem primeru bom spustni seznam imena vnesel v ime Box, nato pritisnite Vnesite tipko, glej posnetek zaslona:

doc spustni meni različne vrednosti 2

2. Nato izberite celice, kamor želite vstaviti spustni seznam, in kliknite datum > Preverjanje podatkov > Preverjanje podatkov, glej posnetek zaslona:

doc spustni meni različne vrednosti 3

3. v Preverjanje podatkov v pogovornem oknu pod Nastavitve izberite jeziček Seznam Iz Dovoli in nato kliknite doc spustni meni različne vrednosti 5 , da izberete seznam imen, ki ga želite uporabiti kot spustne vrednosti v vir besedilno polje. Oglejte si posnetek zaslona:

doc spustni meni različne vrednosti 4

4. Po vstavitvi spustnega seznama z desno miškino tipko kliknite zavihek aktivnega lista in izberite Ogled kode v priročnem meniju in v odprtem Microsoft Visual Basic za aplikacije okno, kopirajte in prilepite naslednjo kodo v prazen modul:

Koda VBA: Prikažite drugačno vrednost s spustnega seznama:

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
    selectedNa = Target.Value
    If Target.Column = 5 Then
        selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("dropdown"), 2, False)
        If Not IsError(selectedNum) Then
            Target.Value = selectedNum
        End If
    End If
End Sub

doc spustni meni različne vrednosti 6

Opombe: V zgornji kodi številka 5 v Če je ciljni stolpec = 5, potem skript je številka stolpca, na kateri je spustni seznam,spustni" v tem selectedNum = Application.VLookup (selectedNa, ActiveSheet.Range ("spustni meni"), 2, False) koda je ime obsega, ki ste ga ustvarili v koraku 1. Lahko jih spremenite v želeno.

5. Nato shranite in zaprite to kodo. Ko izberete element s spustnega seznama, se v isti celici prikaže relativno drugačna vrednost, glejte posnetek zaslona:

doc spustni meni različne vrednosti 7


Predstavitev: ustvarite spustni seznam, vendar v Excelu prikažite različne vrednosti

Kutools za Excel: z več kot 300 priročnimi dodatki za Excel, brezplačno preizkusite brez omejitev v 30 dneh. Prenesite in brezplačno preskusite zdaj!

 

Najboljša pisarniška orodja za produktivnost

🤖 Kutools AI Aide: Revolucionirajte analizo podatkov na podlagi: Inteligentna izvedba   |  Ustvari kodo  |  Ustvarite formule po meri  |  Analizirajte podatke in ustvarite grafikone  |  Prikličite funkcije Kutools...
Priljubljene funkcije: Poiščite, označite ali identificirajte dvojnike   |  Izbriši prazne vrstice   |  Združite stolpce ali celice brez izgube podatkov   |   Krog brez formule ...
Super iskanje: Več kriterijev VLookup    Multiple Value VLookup  |   VLookup na več listih   |   Nejasno iskanje ....
Napredni spustni seznam: Hitro ustvarite spustni seznam   |  Odvisni spustni seznam   |  Večkrat izberite spustni seznam ....
Upravitelj stolpcev: Dodajte določeno število stolpcev  |  Premakni stolpce  |  Preklop stanja vidnosti skritih stolpcev  |  Primerjaj obsege in stolpce ...
Predstavljene funkcije: Mrežni fokus   |  Pogled oblikovanja   |   Velika vrstica formule    Upravitelj delovnih zvezkov in listov   |  Knjižnica virov (Samodejno besedilo)   |  Izbirnik datuma   |  Združite delovne liste   |  Šifriranje/dešifriranje celic    Pošljite e-pošto po seznamu   |  Super filter   |   Poseben filter (filter krepko/ležeče/prečrtano ...) ...
15 najboljših kompletov orodij12 Besedilo Orodja (dodajanje besedila, Odstrani znake,...)   |   50 + Graf Vrste (Gantt Chart,...)   |   40+ Praktično Formule (Izračunajte starost glede na rojstni dan,...)   |   19 vstavljanje Orodja (Vstavite kodo QR, Vstavi sliko s poti,...)   |   12 Pretvorba Orodja (Številke v besede, Pretvorba valut,...)   |   7 Spoji in razdeli Orodja (Napredne kombinirane vrstice, Razdeljene celice,...)   |   ... in več

Napolnite svoje Excelove spretnosti s Kutools za Excel in izkusite učinkovitost kot še nikoli prej. Kutools za Excel ponuja več kot 300 naprednih funkcij za povečanje produktivnosti in prihranek časa.  Kliknite tukaj, če želite pridobiti funkcijo, ki jo najbolj potrebujete...

Opis


Kartica Office prinaša vmesnik z zavihki v Office in poenostavi vaše delo

  • Omogočite urejanje in branje z zavihki v Wordu, Excelu, PowerPointu, Publisher, Access, Visio in Project.
  • Odprite in ustvarite več dokumentov v novih zavihkih istega okna in ne v novih oknih.
  • Poveča vašo produktivnost za 50%in vsak dan zmanjša na stotine klikov miške za vas!

 

Comments (44)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello everyone,

About two years ago, @skyyang posted the following formula, which works perfectly:
Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
Dim xRg As Range
selectedNa = Target.Value
If Target.Column = 5 Then
Set xRg = ActiveWorkbook.Names("DropDown").RefersToRange
selectedNum = Application.VLookup(selectedNa, xRg, 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub


However, I have six sections each needing the same results from the DDL name range. How do I get this formula to apply to more than one column please?

Any help would be greatly appreciated 🙂
This comment was minimized by the moderator on the site
How can I use this formula if the data for the drop down is on a sheet named materials?

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
selectedNa = Target.Value
If Target.Column = 4 Then
selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("Material_List"), 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub
This comment was minimized by the moderator on the site
Can this be applied to certain cells only instead of the whole column? It’s coming back as #N/A for some areas that i don't need this formula for. Thanks
This comment was minimized by the moderator on the site
The code I have used is below:


Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
selectedNa = Target.Value
If Target.Column = 8 Then
selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("codes"), 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub



This works exactly how I need it too, however, when I save, close and then re-open the excel document, this has disappeared from the 'View Code' window and I have to re-insert the code again?????

Please help!
This comment was minimized by the moderator on the site
I have even saved the document as a Excel Macro-Enabled Workbook
This comment was minimized by the moderator on the site
Can you do multiple drop down lists like this on the same worksheet tab? How will the vba code be adjusted to accommodate different lists for the sheet?
This comment was minimized by the moderator on the site
Is there a way to return multiple selections to the same field? I.E. I want to show the numbers for Tedi, Dave and Lucy on a single field seperated by a comma.Many thanks.
This comment was minimized by the moderator on the site
This works for me but is there a way to allow multiple selections in the same cell? I.e. I wanted to return the numbers for Tedi, Lucy and Dave in a single field seperated by a comma?
This comment was minimized by the moderator on the site
Can this be done on different sheets? I mean, on sheet1 the range and on sheet2 the dropdown. How do I have to code this? Thanks.
This comment was minimized by the moderator on the site
Hello, Muhammd,To apply the drop down list in different worksheet, the following code may help you:Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
Dim xRg As Range
selectedNa = Target.Value
If Target.Column = 5 Then
Set xRg = ActiveWorkbook.Names("DropDown").RefersToRange
selectedNum = Application.VLookup(selectedNa, xRg, 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub


Please try, thank you!
This comment was minimized by the moderator on the site
trying to do multiple drop downs sheet 1 , returning different worksheet. Is this possible as when i select in separate dropdown the sam numbers it does not work For example
Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice

selectedNa = Target.Value
If Target.Column = 2 Then
Set xRg = ActiveWorkbook.Names("Supervisors").RefersToRange
selectedNum = Application.VLookup(selectedNa, xRg, 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
selectedNa = Target.Value
End If
End If
selectedNa = Target.Value
If Target.Column = 9 Then
Set xRg = ActiveWorkbook.Names("Earth").RefersToRange
selectedNum = Application.VLookup(selectedNa, xRg, 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
selectedNa = Target.Value

End If
End If
End Sub
This comment was minimized by the moderator on the site
Good morning i hope someone can help me.I used the VBA code above and it worked perfectly giving me my drop down showing me Different Values In Drop Down List Cell.My problem is that I need a second drop down list showing different values in a second list cell, on the same sheet, can anyone help me in doing this Kind Regards Rene
This comment was minimized by the moderator on the site
Se pueden usar diferentes “dropdown” en la misma hoja, para diferentes columnas y con diferentes rangos?Me explico, tengo una hoja en la que los usuarios introducen diferentes datos. En dos columnas 5 y 12 necesito validar la entrada con respecto a dos rangos diferentes de datos. Lo he probado solo con una columna y funciona perfectamente, pero no encuentro la manera de modificar el código VBA para la segunda columna
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