Avatar of kerikeri
kerikeri
Flag for New Zealand asked on

Populate a cell value from a dropdown list

I need to limit the selection of road names.  Thought I would use a dropdown list, but this is quite inadequate.  See simple file where the list of valid roads is in a separate worksheet.  I've also tried using a combo box but can't see how I would link this to a column.  So easy to do in Access!  Hopefully it's just my inexperience with EXCEL...
EEDropdownList.xlsx
Microsoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
kerikeri

8/22/2022 - Mon
Ryan Chong

in C1, you need to put in the Data Validation so that it can refers the value from your list of values.
Ryan Chong

to do that, first go to worksheet: Roads, create a Name.

SnapShot.png
now go back to worksheet: MainSheet, select cell C1, then go to tab: Data > Data Validation and add this.

SnapShot2.png
so now you should able to see a dropdown then.

SnapShot3.pngEEDropdownList_b.xlsx
Wayne Taylor (webtubbs)

In this instance, you might be better off with a Controls Combobox, not a Forms Combobox which you are currently using. Doing so allows the following pertinent properties...

ListFillRange - The range of cells to populate the combobox. Can be multiple columns wide.
BoundColumn - The column from ListFillRange which  returns the selected value. The value isn't necessarily the displayed text.
LinkedCell - The cell which displays the selected value of the combobox.

See the attached example. To view the properties, click Design Mode on the Developers tab, right-click the control and select Properties.
EEDropdownList.xlsx
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Subodh Tiwari (Neeraj)

I think you need a searchable drop down list which gets populated with matching roads as you type.
Please refer to the attached and see if this is what you were trying to achieve.
SearchableCombobox.xlsm
kerikeri

ASKER
Thank you for your quick responses.  Ryan's was the same solution as what my original description was, not really a solution for me.  Wayne's seemed possible, but I couldn't figure out how the LinkedCell requirement could be defined to a relative cell and as I'm using the logic in a data entry form, that doesn't work.  It has to be able to populate a different linked cell for each row .  So Neeraj's is the one that I'm using.  The only thing not so good is it doesn't include the complete list of roads on initially opening.  However, it's definitely a step in the right direction.  Thanks again all of you.
Subodh Tiwari (Neeraj)

I does show the complete list when activated after selecting a cell in column A.
Watch this short video.
https://www.screencast.com/t/nGbNbccB12Y
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
kerikeri

ASKER
Maybe I shouldn't have closed this so quickly.   Hope you don't mind answering further questions about this solution.
SampleSpreadsheet.xlsm
EEComboBox-Question-.docx
Wayne Taylor (webtubbs)

but I couldn't figure out how the LinkedCell requirement could be defined to a relative cell

If added manually, you need to set the LinkedCell property of each combobox individually. Alternatively, you can use the below macro to add the combobox to the current selection of cells. It sets the LinkedCell to the cell to the immediate right of the cell the combobox is in.

Sub AddComboboxes()
        
    Dim cell As Range, cb As OLEObject
    For Each cell In Selection
        Set cb = ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, _
        DisplayAsIcon:=False, Left:=cell.Left, Top:=cell.Top, Width:=cell.Width, Height:=cell.Height)
        With cb
            .LinkedCell = cell.Offset(0, 1).Address
            .Object.BoundColumn = 2
            .ListFillRange = "Roads!A2:B786"
        End With
    Next
    
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Subodh Tiwari (Neeraj)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
kerikeri

ASKER
Thank you for your latest comment Neeraj - I need to apply this to the spreadsheet attached in my last comment:  "The combobox is hidden and sitting in A1 and it appears only when you select any cell in column A which has a data validation and once you click outside the column A, it disappears again. So there is only one combobox sitting on the sheet and it moves to the cell you select in column A. Also the combobox is linked to the selected cell dynamically by the code."   I'm trying to replicate this combo box in my spreadsheet so would like to keep this question open until I've managed to do this.  Thanks, it's one part of my quite busy job right now!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
kerikeri

ASKER
thank you