Vai al contenuto principale

Come eseguire il completamento automatico durante la digitazione nell'elenco a discesa di Excel?

Per un elenco a discesa di convalida dei dati con molti elementi, è necessario scorrere su e giù nell'elenco per trovare quello desiderato o digitare correttamente l'intera parola nella casella di riepilogo. C'è un modo per completare automaticamente l'elenco a discesa quando si digitano i caratteri corrispondenti? Ciò aiuterebbe le persone a lavorare in modo più efficiente nei fogli di lavoro con elenchi a discesa nelle celle. Questo tutorial fornisce due metodi per aiutarti a raggiungerlo.

Fai in modo che gli elenchi a discesa si completino automaticamente con il codice VBA
Completa facilmente gli elenchi a discesa in 2 secondi

Altri tutorial per l'elenco a discesa ...


Fai in modo che gli elenchi a discesa si completino automaticamente con il codice VBA

Si prega di fare quanto segue per completare automaticamente un elenco a discesa dopo aver digitato le lettere corrispondenti nella cella.

Innanzitutto, è necessario inserire una casella combinata nel foglio di lavoro e modificarne le proprietà.
  1. Apri il foglio di lavoro che contiene le celle dell'elenco a discesa che desideri completare automaticamente.
  2. Prima di inserire una casella combinata, è necessario aggiungere la scheda Sviluppatore alla barra multifunzione di Excel. Se la scheda Sviluppatore è visualizzata sulla barra multifunzione, passare al passaggio 3. Altrimenti, procedi come segue per visualizzare la scheda Sviluppatore nella barra multifunzione: Fai clic Compila il > Opzioni per aprire il Opzioni finestra. In questo Opzioni di Excel finestra, fare clic Personalizzazione barra multifunzione nel riquadro di sinistra, controlla il file Costruttori casella, quindi fare clic su OK pulsante. Vedi screenshot:
  3. Clicchi Costruttori > inserire > Casella combinata (controllo ActiveX).
  4. Disegna una casella combinata nel foglio di lavoro corrente. Fare clic con il tasto destro e quindi selezionare Properties dal menu di scelta rapida.
  5. Nel Properties finestra di dialogo, sostituire il testo originale nel file (Nome) campo con TempCombo.
  6. Spegni il Modalità di progettazione cliccando Costruttori > Modalità di progettazione.
Quindi, applica il codice VBA sottostante
  1. Fare clic con il tasto destro sulla scheda del foglio corrente e fare clic Visualizza codice dal menu contestuale. Vedi screenshot:
  2. In apertura Microsoft Visual Basic, Applications Edition finestra, copia e incolla il codice VBA sottostante nella finestra del codice del foglio di lavoro.
    Codice VBA: completamento automatico durante la digitazione nell'elenco a discesa
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'Update by Extendoffice: 2020/01/16
        Dim xCombox As OLEObject
        Dim xStr As String
        Dim xWs As Worksheet
        Dim xArr
        
        Set xWs = Application.ActiveSheet
        On Error Resume Next
        Set xCombox = xWs.OLEObjects("TempCombo")
        With xCombox
            .ListFillRange = ""
            .LinkedCell = ""
            .Visible = False
        End With
        If Target.Validation.Type = 3 Then
            Target.Validation.InCellDropdown = False
            Cancel = True
            xStr = Target.Validation.Formula1
            xStr = Right(xStr, Len(xStr) - 1)
            If xStr = "" Then Exit Sub
            With xCombox
                .Visible = True
                .Left = Target.Left
                .Top = Target.Top
                .Width = Target.Width + 5
                .Height = Target.Height + 5
                .ListFillRange = xStr
                If .ListFillRange = "" Then
                    xArr = Split(xStr, ",")
                    Me.TempCombo.List = xArr
                End If
                .LinkedCell = Target.Address
            End With
            xCombox.Activate
            Me.TempCombo.DropDown
        End If
    End Sub
    Private Sub TempCombo_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
        Select Case KeyCode
            Case 9
                Application.ActiveCell.Offset(0, 1).Activate
            Case 13
                Application.ActiveCell.Offset(1, 0).Activate
        End Select
    End Sub
  3. Rassegna Stampa altro + Q contemporaneamente i tasti per chiudere il file Applicazioni Microsoft Visual Basic finestra.

D'ora in poi, quando si fa clic su una cella dell'elenco a discesa, l'elenco a discesa verrà richiesto automaticamente. Puoi iniziare a digitare la lettera per completare automaticamente l'elemento corrispondente nella cella selezionata. Vedi screenshot:

Nota: Questo codice non funziona per le celle unite.

Crea facilmente il completamento automatico dell'elenco a discesa in 2 secondi

Per la maggior parte degli utenti di Excel, il metodo VBA di cui sopra è difficile da padroneggiare. Ma con il Elenco a discesa ricercabile caratteristica di Kutools for Excel, puoi abilitare facilmente il completamento automatico per gli elenchi a discesa di convalida dei dati in un intervallo specificato in soli 2 secondi. Inoltre, questa funzionalità è disponibile per tutte le versioni di Excel.

Consiglio: Prima di applicare questo strumento, installare Kutools for Excel in primo luogo. Vai al download gratuito ora.

  1. Per abilitare il completamento automatico negli elenchi a discesa, seleziona prima l'intervallo con i menu a discesa. Quindi, vai a Kutools scheda, scegliere Menu `A tendina > Rendi ricercabile l'elenco a discesa, pop-up automatico.
  2. Nel Rendi ricercabile l'elenco a discesa finestra di dialogo, fare clic su OK pulsante per salvare le impostazioni.
Risultato

Una volta completata la configurazione, facendo clic su una cella dell'elenco a discesa all'interno dell'intervallo specificato verrà visualizzata una casella di riepilogo. Quando si immettono caratteri, purché un elemento corrisponda esattamente, l'intera parola viene immediatamente evidenziata nella casella di riepilogo e può essere popolata nella cella dell'elenco a discesa semplicemente premendo il tasto Invio.

Note:: Per applicare questa funzione, per favore scarica e installa Kutools per Excel Primo. O puoi fare clic per saperne di più su questa funzionalità.

Articoli correlati:

Come creare un elenco a discesa con più caselle di controllo in Excel?
Molti utenti di Excel tendono a creare un elenco a discesa con più caselle di controllo per selezionare più elementi dall'elenco alla volta. In realtà, non puoi creare un elenco con più caselle di controllo con la convalida dei dati. In questo tutorial, ti mostreremo due metodi per creare un elenco a discesa con più caselle di controllo in Excel. Questo tutorial fornisce il metodo per risolvere il problema.

Crea un elenco a discesa da un'altra cartella di lavoro in Excel
È abbastanza facile creare un elenco a discesa di convalida dei dati tra i fogli di lavoro all'interno di una cartella di lavoro. Ma se i dati dell'elenco necessari per la convalida dei dati si trovano in un'altra cartella di lavoro, cosa faresti? In questo tutorial imparerai come creare un elenco a discesa da un'altra cartella di lavoro in Excel in dettaglio.

Crea un elenco a discesa ricercabile in Excel
Per un elenco a discesa con numerosi valori, trovarne uno corretto non è un lavoro facile. In precedenza abbiamo introdotto un metodo di completamento automatico dell'elenco a discesa quando si immette la prima lettera nella casella a discesa. Oltre alla funzione di completamento automatico, è anche possibile rendere ricercabile l'elenco a discesa per migliorare l'efficienza lavorativa nel trovare i valori corretti nell'elenco a discesa. Per rendere ricercabile l'elenco a discesa, prova il metodo in questo tutorial.

Compilare automaticamente altre celle quando si selezionano i valori nell'elenco a discesa di Excel
Supponiamo che tu abbia creato un elenco a discesa basato sui valori nell'intervallo di celle B8: B14. Quando si seleziona un valore nell'elenco a discesa, si desidera che i valori corrispondenti nell'intervallo di celle C8: C14 vengano inseriti automaticamente in una cella selezionata. Per risolvere il problema, i metodi in questo tutorial ti faranno un favore.

Altri tutorial per l'elenco a discesa ...

I migliori strumenti per la produttività in ufficio

🤖 Assistente AI di Kutools: Rivoluziona l'analisi dei dati basandosi su: Esecuzione intelligente   |  Genera codice  |  Crea formule personalizzate  |  Analizzare i dati e generare grafici  |  Richiama le funzioni di Kutools...
Funzioni popolari: Trova, evidenzia o identifica i duplicati   |  Elimina righe vuote   |  Combina colonne o celle senza perdere dati   |   Round senza formula ...
Super ricerca: VLookup a criteri multipli    VLookup a valori multipli  |   VLookup su più fogli   |   Ricerca fuzzy ....
Elenco a discesa avanzato: Crea rapidamente un elenco a discesa   |  Elenco a discesa dipendente   |  Elenco a discesa a selezione multipla ....
Gestore di colonna: Aggiungi un numero specifico di colonne  |  Sposta colonne  |  Attiva/disattiva lo stato di visibilità delle colonne nascoste  |  Confronta intervalli e colonne ...
Funzionalità in primo piano: Messa a fuoco della griglia   |  Vista di progettazione   |   Grande barra delle formule    Gestore di cartelle di lavoro e fogli   |  Resource Library (Testo automatico)   |  Date picker   |  Combina fogli di lavoro   |  Crittografa/decrittografa le celle    Invia e-mail per elenco   |  Super filtro   |   Filtro speciale (filtro grassetto/corsivo/barrato...) ...
I 15 migliori set di strumenti12 Testo Strumenti (aggiungi testo, Rimuovi personaggi, ...)   |   50+ Grafico Tipi (Diagramma di Gantt, ...)   |   40+ Pratico Formule (Calcola l'età in base al compleanno, ...)   |   19 Inserimento Strumenti (Inserisci il codice QR, Inserisci immagine dal percorso, ...)   |   12 Conversione Strumenti (Numeri in parole, Conversione di valuta, ...)   |   7 Unisci e dividi Strumenti (Combina righe avanzate, Celle divise, ...)   |   ... e altro ancora

Potenzia le tue competenze di Excel con Kutools per Excel e sperimenta l'efficienza come mai prima d'ora. Kutools per Excel offre oltre 300 funzionalità avanzate per aumentare la produttività e risparmiare tempo.  Fai clic qui per ottenere la funzionalità di cui hai più bisogno...

Descrizione


Office Tab porta l'interfaccia a schede in Office e semplifica notevolmente il tuo lavoro

  • Abilita la modifica e la lettura a schede in Word, Excel, PowerPoint, Publisher, Access, Visio e Project.
  • Apri e crea più documenti in nuove schede della stessa finestra, piuttosto che in nuove finestre.
  • Aumenta la produttività del 50% e riduce ogni giorno centinaia di clic del mouse!
Comments (325)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi, many thanks for this material. It helped a lot.
This comment was minimized by the moderator on the site
Hello,

following on from my last comment:

I'm setting up 'standard' rows with the dropdown lists in them. These I'm wanting to copy below into an extensive spreadsheet.
Unfortunately the dropdown's don't copy down when I do that after using the VBA.
Is there a way to do whats described above?

Cheers,
Catherine
This comment was minimized by the moderator on the site
Hi Catherine,
The autocomplete drop-down lists generated by VBA code cannot be copied. You can only copy selected items that are displayed in the drop-down cell. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
Hello,

Have implemented this successfully, so thank you for this page and code.
But now I have an associated problem...:

After doing all of the above points, the code works as described, but I cannot do any undo/redo actions in the entire spreadsheet.
Is there a way to turn this combo box on for when I want to work with the dropdowns and off for when I want to work in other cells? so that the undo/redo actions are possible again?
and note, yes I have turned the design mode off after doing the above steps, but it still doesn't help the problem.

Cheers,
Catherine
This comment was minimized by the moderator on the site
Hi Catherine Foley,
If you want to use the undo operation on cells other than the drop-down cells, the following VBA code can help you. Please give it a try.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Update by Extendoffice: 2022/09/22
    Dim xCombox As OLEObject
    Dim xStr As String
    Dim xWs As Worksheet
    Dim xArr
    
    On Error Resume Next

    Set xWs = Application.ActiveSheet
    
    Set xCombox = xWs.OLEObjects("TempCombo")
    If Target.Validation.Type <> 3 Then
        If xCombox.Visible Then
            xCombox.Visible = False
        End If
        Exit Sub
    End If
    
    With xCombox
        .ListFillRange = ""
        .LinkedCell = ""
'        .Visible = False
    End With

    Target.Validation.InCellDropdown = False
    Cancel = True
    xStr = Target.Validation.Formula1
    xStr = Right(xStr, Len(xStr) - 1)
    If xStr = "" Then Exit Sub
    With xCombox
        .Visible = True
        .Left = Target.Left
        .Top = Target.Top
        .Width = Target.Width + 5
        .Height = Target.Height + 5
        .ListFillRange = xStr
        If .ListFillRange = "" Then
            xArr = Split(xStr, ",")
            Me.TempCombo.List = xArr
        End If
        .LinkedCell = Target.Address
    End With
    xCombox.Activate
    Me.TempCombo.DropDown

End Sub
Private Sub TempCombo_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    Select Case KeyCode
        Case 9
            Application.ActiveCell.Offset(0, 1).Activate
        Case 13
            Application.ActiveCell.Offset(1, 0).Activate
    End Select
End Sub
This comment was minimized by the moderator on the site
I hope now it will be upload
This comment was minimized by the moderator on the site
This code works really well for a single drop down. However, if I have 5 dropdowns using the same list of values but they need to operate independently of each other how is that accomplished? Despite my best efforts, if I put more than one combo box on the page, any selection is one is mirrored in the other.
This comment was minimized by the moderator on the site
Hi Mbuchmeier,Only need one combo box on the page. The code works on all drop-down lists in current page. You just need to manually click on the drop-down list cell to activate the combo box.
This comment was minimized by the moderator on the site
Hi crystal,
I am working with the combo box (The VBA code from 2021/11/05). It is working great and very useful but there are 2 issues:1. Issue #1: Usually when you work on any cell in Excel, there is indication on the row number which indicate which row you work about. When the combo box is opened this indication is missing2.  Issue #2: When the combo box is opened in the last column of the dynamic table, then it isn't  working as usual: when I select value from the list, the cell remain empty until I move the cursor to another cell
Attached screenshot.
Thank in advance
This comment was minimized by the moderator on the site
Hi Yoni,Thanks for your feedback. For the issues you mentioned:1. Issue #1: Excel does not highlight the row number when selecting an object in the worksheet. Since we use a combo box to replace the data validation drop-down list to handle the autocomplete operation, we can't show the indication in this case;2. Issue #2: I have tried as you described, but the problem cannot be reproduced. The screenshot you attached does not display, you need to save the screenshot and uplode it via the "Upload files" button below.
This comment was minimized by the moderator on the site
Hi Crystal,Thanks a lot for your response. Attached the screenshot. hope it will work now
This comment was minimized by the moderator on the site
Hi Yoni,Sorry for the inconvenience. The screenshot you uploaded is still not shown on the page. You need to save the screenshot on your disk in advance and then uplode it via the "Upload files" button. See the attached screenshot.
This comment was minimized by the moderator on the site
will, thank you is not enugh :::: alot of thank you then ;;;;; that worked like magic :)
This comment was minimized by the moderator on the site
Yeah, basically completely useless.  Want the cell to auto-complete when typing in a cell using list data validation.Tried this, and now I have to start over from scratch because I can't Undo it.  Thanks.Also loaded with syntax errors.
This comment was minimized by the moderator on the site
It works as it should be except for two things, first, there is no validation after insertion. i.e. if I typed anything at the combo then clicked enter it will accept the typed value while it should not do this since the data validation is being used to prevent such behaviors and make sure that the entered data is from selected range. Second, at the data validation list, sometimes I use big range with empty cells and select ignore empty at validation list but the combo takes all the range and shows it, will be nice to remove the empty cells from the combo range.
Thanks & hope you can implement these things to make it perfect.
This comment was minimized by the moderator on the site
Hi, AhmedThe VBA below helps to solve the problem of blank cells. Since the Combo box accepts the value that are not in the list, we still can't find a way to solve this problem. Sorry for the inconvenience.
<div data-tag="code">Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Update by Extendoffice: 2021/11/05
Dim xCombox As OLEObject
Dim xStr As String
Dim xWs As Worksheet
Dim xArr, xArr1
Dim xRg As Range
Dim xSrc As Variant
Dim xI, xJ, xIndex, xCount As Integer

Set xWs = Application.ActiveSheet
On Error Resume Next
Set xCombox = xWs.OLEObjects("TempCombo")
With xCombox
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
If Target.Validation.Type = 3 Then
Target.Validation.InCellDropdown = False
Cancel = True
xStr = Target.Validation.Formula1
xStr = Right(xStr, Len(xStr) - 1)
If xStr = "" Then Exit Sub
Set xRg = Range(xStr)
If xRg Is Nothing Then
xArr1 = Split(xStr, ",")
Else
ReDim xArr1(0 To xRg.Count - 1)
For xI = 0 To xRg.Count - 1
xArr1(xI) = xRg.Item(xI + 1).Value
Next
End If
xI = 0
xCount = UBound(xArr1) + 1
For xJ = 0 To UBound(xArr1)
If Replace(xArr1(xJ), " ", "") = "" Then xCount = xCount - 1
Next
ReDim xArr(0 To xCount - 1)
xIndex = 0
For xJ = 0 To UBound(xArr1)
If Replace(xArr1(xJ), " ", "") <> "" Then
xArr(xIndex) = xArr1(xJ)
xIndex = xIndex + 1
End If
Next
xStr = ""
With xCombox
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = xStr
If .ListFillRange = "" Then
'xArr = Split(xStr, ",")
Me.TempCombo.List = xArr
End If
.LinkedCell = Target.Address
End With
xCombox.Activate
Me.TempCombo.DropDown
End If
End Sub
Private Sub TempCombo_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case 9
Application.ActiveCell.Offset(0, 1).Activate
Case 13
Application.ActiveCell.Offset(1, 0).Activate
End Select
End Sub
This comment was minimized by the moderator on the site
Hi Crystal,
I am working with the combo box (The VBA code from 2021/11/05). It is working great and so useful! thanks a lot.
I found the source of my problem. There was a line of freeze panes which override the combo box.
The only problem now is that the Undo is not working. Any idea?
Thanks in advanced,
Yoni
This comment was minimized by the moderator on the site
Hi,
The code does not support Undo. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
Thanks. Maybe do you know why Worksheet_Change event is not firing once I choose value from the combo box?
This comment was minimized by the moderator on the site
Hi, could you please doublecheck this code, when I use it instead of the dropdown list appearing, the source for the dropdown appears instead. This is the exact function I want, could you please fix it.
This comment was minimized by the moderator on the site
If you use a named range or something similar, like I have with a table column, it will display the named range name instead of the values in that named range. To get what you want, you need to change the xStr to display the worksheet range of that named range, since the .ListFillRange does not take in named ranges directly. This should accomplish it : dim RangeAddress as String: RangeAddress = Range(YourNamedRange).addressand then make the xStr something like this: xStr = "YourWorksheetNameWithTheNamedRangeInIt!" & RangeAddress (important: add the '!' for the sheet reference)
This will make your xStr look something like: NamedRangeSheet!$A$1:$A$5
xStr = Right(xStr, Len(xStr) - 1)

If .ListFillRange = "" Then
xArr = Split(xStr, ",")
Me.TempCombo.List = xArr
End If

with these adjustments your combobox should display the list values instead of the source
This comment was minimized by the moderator on the site
Hi Syu,Sorry I don't quite understand your description. Can you try to be more specific of it?After applying the VBA code mentioned in the above method, when the cell with the data validation drop-down list is checked, the drop-down list turn into a combo box, and then all the items in the list are listed. 
This comment was minimized by the moderator on the site
do you have an example file please?
This comment was minimized by the moderator on the site
Hello. The code is very cool. Please make sure that the formula "INDIRECT" is carried out and displayed. It is very necessary
This comment was minimized by the moderator on the site
The code is not working for a validation list which is created by vba code and the source is a named range
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