Populate a cell value from a dropdown list

kerikeri
kerikeri used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead

Commented:
in C1, you need to put in the Data Validation so that it can refers the value from your list of values.
Ryan ChongSoftware Team Lead

Commented:
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
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
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
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

Author

Commented:
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)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
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

Author

Commented:
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
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

Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015
Commented:
QUESTION:  I don’t understand why you chose to add another column with a heading Roads in the Roads worksheet, and use that as your Named value?
A new list gets populated in column E based on what you type in the combobox e.g. if you type "ara" in the combobox a new list of Roads which have ara in them will be inserted in the column E and that will be used to fill the combobox.

Question:  Where is the combobox?  Is it somehow in the same cell as the data validation?  This is what I need to apply to my real spreadsheet and it’s quite difficult to see where it fits.  Sorry, hope you don’t mind elaborating.
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.

Author

Commented:
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!

Author

Commented:
thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial