Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Populate Combobox Values at a click of button

Posted on 2011-03-05
4
Medium Priority
?
639 Views
Last Modified: 2012-05-11
I want to populate the Combobox with the list of predefined values declared in another sheet in same excel at a click of command button



0
Comment
Question by:srikanthv2322
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 2000 total points
ID: 35044804
Please amend as applicable.

Private Sub CommandButton1_Click()
    '~~> This will populate from Row 1 to Row 10
    '~~> from Col A in Sheet 2
    For i = 1 To 10
        ComboBox1.AddItem Sheets("Sheet2").Range("A" & i).Value
    Next
End Sub

Open in new window


Sid
0
 
LVL 14

Expert Comment

by:Zack Barresse
ID: 35045024
I would amend Sid's code to include a clear functionality, which will not make your list "double" when you click the button a second time...
Private Sub CommandButton1_Click()
    Dim i As Long
    ComboBox1.Clear
    For i = 1 To 10
        ComboBox1.AddItem Sheets("Sheet2").Range("A" & i).Value
    Next
End Sub

Open in new window

Or, you can use another method, one I prefer, to enter the data all at once instead of looping (I hate looping)...
Private Sub CommandButton1_Click()
    ComboBox1.Clear
    ComboBox1.List = Sheets("Sheet2").Range("A1:A10").Value
End Sub

Open in new window

HTH
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35045028
Thanks Zack

I missed on "ComboBox1.Clear". Nice catch!

Yeah, I completely agree with you on "Looping".

Sid
0
 
LVL 14

Expert Comment

by:Zack Barresse
ID: 35045054
Just another way to skin the cat.  I'm not really sure what the OP's end-game is with this particular query, which is why I posted the secondary routine.  It may in fact be a loop is what is called for - I have no idea! :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question