Dropdown list autocomplete and increment (VBA)

ssigl

New Member
Joined
Jan 25, 2017
Messages
8
Hi everyone!

What I am looking to do is create a dropdown that will autosuggest/autocomplete from a list of products in Column A when starting to type in the dropdown. When confirming the product (by pressing enter), I would like if it could automatically reset, but also add an increment of +1 in the cell (in column B) next to the product name.

How would I go about doing this?

Thanks in advance!
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Try this:-
I have assumed that the "DropDown" is "Combobox1" and it is in a you data sheet, not a "Userform".
Paste this code in the sheet Module.
Right click sheet tab select "View Code"> vbwindow appears> paste at top of Vbwindow > close Vbwindow

Code:
Option Explicit
[COLOR=navy]Dim[/COLOR] Dic [COLOR=navy]As[/COLOR] Object
Private [COLOR=navy]Sub[/COLOR] ComboBox1_GotFocus()
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range, n [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
[COLOR=navy]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
        [COLOR=navy]Set[/COLOR] Dic = CreateObject("scripting.dictionary")
            Dic.CompareMode = vbTextCompare
        [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
            [COLOR=navy]Set[/COLOR] Dic(Dn.Value) = Dn
        [COLOR=navy]Next[/COLOR]
[COLOR=navy]With[/COLOR] ComboBox1
    .ListFillRange = ""
    .List = Application.Transpose(Dic.keys)
    .MatchEntry = fmMatchEntryComplete
[COLOR=navy]End[/COLOR] With
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]



Private [COLOR=navy]Sub[/COLOR] ComboBox1_KeyDown(ByVal KeyCode [COLOR=navy]As[/COLOR] MSForms.ReturnInteger, ByVal Shift [COLOR=navy]As[/COLOR] Integer)
    [COLOR=navy]If[/COLOR] KeyCode = 13 [COLOR=navy]Then[/COLOR]
       If ComboBox1.Value <> "" Then
             Dic(ComboBox1.Value).Offset(, 1).Value = Dic(ComboBox1.Value).Offset(, 1).Value + 1
             ComboBox1.ListIndex = -1
      End if [COLOR=navy]
  End[/COLOR] If
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:

Forum statistics

Threads
1,082,131
Messages
5,363,337
Members
400,726
Latest member
Shahzad Taimoor

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top