Solved

Populate Combobox Values at a click of button

Posted on 2011-03-05
4
630 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
  • 2
  • 2
4 Comments
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now