Email:      Pass:    Pass?
Advertisements


Free Excel Forum

How Do You Populate A Combobox?

Forum Register
Search Excel Forum Posts, Tutorials, Macros, Tips, and More

I'm trying to populate a ComboBox with a list of choices, but not having much luck. I'm not sure what I'm doing wrong.

Code:

Private Sub ComboBox1_Change()
    ComboBox1.Style = fmStyleDropDownList
    ComboBox1.AddItem "PDN"
    ComboBox1.ListIndex = 0
    
End Sub


I think this should be it's own post, but I also posted the question in another thread that I wrote. See this link.

I don't want anyone to think that I'm trying to double-post and waste your time. I really appreciate all the help.

Thanks,

-gshock


Similar Excel Video Tutorials

Helpful Excel Macros

Enter Text/Characters with a Double-Click of the Mouse
- This macro allows you to enter any text or number, that you specify, in a cell on which you double-click. In the exampl
Add a Drop Down Menu to a Cell in Excel - Data Validation Macro
- Add a drop down menu or list to a cell in Excel with this free Excel macro. This is a great little macro that allows yo
Display The Actual Link / Email Address From Links in Excel - UDF
- Display the actual link or email address from links within Excel with this UDF. This user defined function pulls the ac
Complete Guide to Printing in Excel Macros - PrintOut Method in Excel
- This free Excel macro illustrates all of the possible parameters and arguments that you can include in the PrintOut Meth
Get Comment Text from Cell Comments in Excel - UDF
- This free Excel UDF outputs all text from a comment in Excel. This benefit of this UDF is that it doesn't display the c

Similar Topics







Running Excel 2003 on Windows XP.

For some reason this code is intermitant and when it does work the only item in the list that populates is the first one. I've created a ComboBox in worksheet 1 and want to populate it with 7 items from VBA. I do not want to populate it from an array or range of cells. In addition, the code works if I place it in the worksheet_activate event, but then requires that I select the second worksheet and reselect the first. Any help would be appreciated!

Private Sub Workbook_Open()
ComboBox1.AddItem "One"
ComboBox1.AddItem "Two"
ComboBox1.AddItem "Three"
ComboBox1.AddItem "Four"
ComboBox1.AddItem "Five"
ComboBox1.AddItem "Six"
ComboBox1.AddItem "Seven"
End Sub


I figured out how to populate the ComboBox, but I have to manually step through the code to do it. How do I get it to populate the values when the spreadsheet is opened?

Then, what I want to do is have the cell formula depend on one of two selections in the ComboBox.

Here's my code for the box.

Code:

Private Sub UserForm_Initialize()
    ComboBox1.AddItem "Bucket"
    ComboBox1.AddItem "Nozzle"
End Sub


Or should I use this one?
Code:

Private Sub ComboBox1_Change()
    ComboBox1.AddItem "Bucket"
    ComboBox1.AddItem "Nozzle"
End Sub


Either way, I don't know how to make it populate the ComboBox automatically. Each time I step through the code, it re-adds both items to the list so that the items keep duplicating.


i need an activex combobox to allow users to have the following three choices "m/s", "ft/s", "knots"

this list will grow to more than three so instead of using the .additem line I would like to use an array...

this isn't working..

Code:

Private Sub ComboBox1_DropButtonClick()

'declarations
Dim i As Integer
Dim a As Variant

'clear the combobox
ComboBox1.Clear

'replace the three lower comments with an array
'ComboBox1.additem "m/s"
'ComboBox1.additem "ft/s"
'ComboBox1.additem "knots/s"

a = Array("m/s", "ft/s", "knots")

'populate each row in combobox with array variables

For i = 0 To 2
    ComboBox1.List(i, 0) = a(i)
Exit For
Next i

End Sub


... index array property error... i have tried using many other variation of this code...

Also on a side note....
is the dropbuttonclick the best procedure to populate the combox?

Ideally i think i want this to load when the document is opened... but i can't seem to get that to work...

I've embedded all sorts of intelligence into the spreadsheet...but i'm having real problems getting this combobox to what i want it to....

Thanks!


Hi all, I've been lurking for a bit but I finally ran into a problem that I couldn't find with the search.

I have a few worksheets and some have combobox's with lists, the only way I could get them to populate the list is to run the worksheet_activate() command like so:

Private Sub Worksheet_Activate()
ComboBox1.Clear
ComboBox1.AddItem ""
ComboBox1.AddItem "Ethane"
ComboBox1.AddItem "Propane"
ComboBox1.AddItem "Propylene"
ComboBox1.AddItem "n-Butane"
ComboBox1.AddItem "i-Butane"
ComboBox1.AddItem "Gasoline"
'ComboBox1.AddItem "Other"'
ComboBox1.Text = ComboBox1.List(0)
End Sub

However the combobox resets everytime I leave the worksheet or the Macro runs the solver. I know it is because Activate command, but I tried to use the workbook_open() but I could not get that to call the various combobox's in the various sheets to activate them. Or even a single one for that matter. I also want to avoid coding the list into the workbook itself because I don't want the end users to accidentally delete the list. Any suggestions?


I received the following code from a question I had earlier. It prefills ComboBox1 in a UserForm with numbers ranging from -3 to +3 and is defaulted to 0. Is there a way to make this code applicable to multiple ComboBoxes without copying it over and over and changing the number? Like maybe something like ComboBox1,3,6,11,14,23,65.AddItem "+3" and so forth? I know that doesn't work, I'm just trying to streamline.

Code:

Private Sub UserForm_Initialize()
    
    ComboBox1.AddItem "+3"
    ComboBox1.AddItem "+2"
    ComboBox1.AddItem "+1"
    ComboBox1.AddItem "0"
    ComboBox1.AddItem "-1"
    ComboBox1.AddItem "-2"
    ComboBox1.AddItem "-3"
    ComboBox1.Value = "0"    'Default as 0
    
End Sub





The code works only if I click the run bottom. However, I would like to have the code run automatically and populate the combobox on its own. What am I missing?

Code:

Private Sub Userform_Activate()
With ComboBox1  'this loads the combo
    .AddItem "N/A"
    .AddItem "KCl"
    .AddItem "NaCl"
    .AddItem "CaCl2"
    .Text = ComboBox1.List(0)
End With
End Sub
Private Sub ComboBox1_Change() 'this writes the selected value to the worksheet
Range("A3") = ComboBox1.Value
End Sub





Hey,

First I would like to say my name is Brad and this is my first time at the forum so hey to everyone. My problem is this, I have two combo boxes working together as variable to assign cell positions for a data sheet. The combo box works, but whenever it is set to case 0, the case variable will be thrown off by the entire length value of the chart. For example here is the code:

Code:

Dim a As Integer
Dim b As Integer
Dim c As Integer
 
Private Sub UserForm_Initialize()
  
    ComboBox1.AddItem "1"        'ListIndex = 0
    ComboBox1.AddItem "2"        'ListIndex = 1
    ComboBox1.AddItem "3"        'ListIndex = 2
    ComboBox1.AddItem "4"        'ListIndex = 3
    ComboBox1.AddItem "5"        'ListIndex = 4
    ComboBox1.AddItem "6"        'ListIndex = 5
    ComboBox1.AddItem "7"        'ListIndex = 6
    ComboBox1.AddItem "8"        'ListIndex = 7
    ComboBox1.AddItem "9"        'ListIndex = 8
    ComboBox1.AddItem "10"       'ListIndex = 9
    ComboBox1.AddItem "11"       'ListIndex = 10
    ComboBox1.AddItem "12"       'ListIndex = 11
    ComboBox1.AddItem "13"       'ListIndex = 12
    ComboBox1.AddItem "14"       'ListIndex = 13
    ComboBox1.AddItem "15"       'ListIndex = 14
    ComboBox1.AddItem "16"       'ListIndex = 15
    
    ComboBox2.AddItem "1"        'ListIndex = 0
    ComboBox2.AddItem "2"        'ListIndex = 1
    ComboBox2.AddItem "3"        'ListIndex = 2
    ComboBox2.AddItem "4"        'ListIndex = 3
    ComboBox2.AddItem "5"        'ListIndex = 4
    ComboBox2.AddItem "6"        'ListIndex = 5
    ComboBox2.AddItem "7"        'ListIndex = 6
  
    'Use drop-down list
    ComboBox1.Style = fmStyleDropDownList
    ComboBox2.Style = fmStyleDropDownList
    'Combo box values are ListIndex values
    ComboBox1.BoundColumn = 0
    ComboBox2.BoundColumn = 0
    'Set combo box to first entry
    ComboBox1.ListIndex = 0
    ComboBox2.ListIndex = 0
End Sub

Private Sub ComboBox1_Click()
    Sheets("RawData").Select
    Select Case ComboBox1.Value
    
    Case 0
    a = 5

    Case 1
    a = 6
             
    Case 2
    a = 7
    
    Case 3
    a = 8
    
    Case 4
    a = 9
    
    Case 5
    a = 10

    Case 6
    a = 11
             
    Case 7
    a = 13
    
    Case 8
    a = 14
    
    Case 9
    a = 15
    
    Case 10
    a = 16
    
    Case 11
    a = 17

    Case 12
    a = 18
             
    Case 13
    a = 19
    
    Case 14
    a = 20
    
    Case 15
    a = 21
      
      End Select
    
End Sub


Private Sub ComboBox2_Click()
    Select Case ComboBox2.Value
    
    Case 0
    b = 4
    
    Case 1
    b = 5
    
    Case 2
    b = 6
        
    Case 3
    b = 7
    
    Case 4
    b = 8
    
    Case 5
    b = 9
    
    Case 6
    b = 10
        End Select
    
End Sub


Private Sub cmdCorrect_Click()
'Sheets("RawData").Range("e34").Value = a
'Sheets("RawData").Range("f34").Value = b
c = 5

For counter = 1 To 13
    Sheets("Results").Cells(a, b).Value = Cells(c, 5)
    a = a + Sheets("RawData").Range("g4").Value         'increments to next frequency
    
    b = b
    c = c + 1
Next counter

frmExport.Hide

End Sub


now for example if I were to pick (case 0, case 1) the cell position wouldnt start in cell in E5. the case 0 would actually would actually take that a = 5 and add the last "a" value from the counter. It only does this when the case is 0. I do not understand why this is happening. I hope I explained this well enough. Thanks to anyone who helps me in advance.[/quote]

edit:
also, Sheets("RawData").Range("g4") is a number used to increment however many of each readings there are. it doesn't have anything to do with the problem just thought I'de mention it.


Hi

I have a Combobox and i need the user to make a selection from the list i.e first line says Please select. How can i make a message box appear (when pressing a command button) to say "Please make a selection from the list"

I have load the combobox using the code below

Private Sub UserForm_Initialize()
ComboBox1.AddItem "Vertical"
ComboBox1.AddItem "Roller"
ComboBox1.AddItem "Venetian"
ComboBox1.AddItem "Roman"
ComboBox1.AddItem "Pleated"
ComboBox1.AddItem "Woodweave"
ComboBox1.AddItem "Dutch blind"
ComboBox1.AddItem "Foldaway awning"
ComboBox1.AddItem "S32 shutter"
ComboBox1.AddItem "Mini safe shutter"
ComboBox1.AddItem "S53 shutter"
ComboBox1.AddItem "Commerical shutter"
ComboBox1.AddItem "Repair shutter"
ComboBox1.AddItem "Repair blind"
ComboBox1.AddItem "Repair awning/dutch/recover"
End Sub

Many thanks


Hi All

I hope someone can help. On a UserForm I have added a ComboBox and populate the ComboBox via code i.e.

Private Sub UserForm_Initialize()
ComboBox1.AddItem "EXTASS/"
ComboBox1.AddItem "AON3/"
ComboBox1.AddItem "COM3/"
ComboBox1.AddItem "ICT3/"
ComboBox1.AddItem "AON4/"
ComboBox1.AddItem "COM4/"
ComboBox1.AddItem "ICT4/"
End Sub

The list of items are Prefixes and the user needs to key in a number at the end i.e. if the user selects AON4/ they would type a number or Month and Number after it i.e. AON4/356 or AON4/Aug07.

The problem I am having is after a selection is made from the drop down list the selected item is displayed but is greyed out. The user has to click the ComboBox just after i.e. AON4/ to set the focus and key in their data. What I require is that the focus is set to the end of the prefix after an item from the list is selected so that the user can key in, rather than selecting the ComboBox and key in. I know its only one more mouse click but it bugs me. I tried;

Private Sub ComboBox1_Change()
UserForm1.ComboBox1.SetFocus
End Sub

but this did not work. Any ideas? Thanks in advance.


Thanks to some earlier help, I've got the combobox working correctly, but I'm trying to populate a text box in my userform based on the contents of the combobox using Vlookup. I've got the worksheet Vlookup down, but I'm struggling with this one. I've tried several things, but not getting too far. This is where I'm at right now.

Code:

Private Sub ComboBox1_Change()
    Me.Combobox1.Value = Format(Me.Combobox1.Value, "mm/dd/yy")
    Me.TextBox1.Value = Application.WorksheetFunction.VLookup(Me.Combobox1.Value, Range("$C$131:$D$146"), 2, True)

End Sub

Private Sub UserForm_Initialize()
   Me.Combobox1.RowSource = "c131:c146"
   Me.Combobox1.Value = Format(Me.Combobox1.Value, "mm/dd/yy")
End Sub


Am I close?

Thanks,

Dean


Here's the code for my drop down list. But when I open the workbook, I have to re-run the macro to get it to populate. How can I modify this code so that I always have the list populated?

Code:

Sub Uersform_Initialize()
ComboBox1.Clear
Dim myrange As Variant
Dim graphRow As Variant

    Me.ComboBox1.List = Sheet1.Range("A3:A338").Value
    
    ComboBox1.Style = fmStyleDropDownList

    ComboBox1.ListIndex = 0
       
 End Sub





hi again,

this question is somewhat related to my previous post regarding moving sheets using combobox. That thread was solved with the help of richard. Since this is a new query I manage to post another thread for it. My question is how to clear a combobox used in form. I have a userform with a combobox and and append button. I want the combobox to be cleared when clicking the append button so that all will be blank. similar to like if a user will start add a new record all textbox will be blank making it ready for new input something like that.

I did used the codes with no luck:

Code:

.combobox1.value=vbNullString
.combobox1.rowsource=""
.combobox1.value=""


Any ideas?

Thanks

Burke


ok i have a combo box on a form and it gives them a list. and whatever they choose i have it copied into ProductDatabse sheet column G

the only problem is that when they select from the list ex: bread or beverage

it doesnt copy bread or beverage into ProductDatabse column G it actually copies a number like 0 or 4

so if they person chooses beverage (first item on list), it puts 0 in the Product Database column G

if they choose salad (fifth item on list), it puts a 4 in the ProductDatabase column G.. what i want it to do is put Salad in the column G or Beverage not a number.. here is the coding for the combobox

Private Sub UserForm_Click()
ComboBox1.AddItem "beverage"
ComboBox1.AddItem "bread"
ComboBox1.AddItem "chips"
ComboBox1.AddItem "entree"
ComboBox1.AddItem "salad"
ComboBox1.AddItem "sauce"
ComboBox1.AddItem "snack"
ComboBox1.AddItem "soup"
ComboBox1.AddItem "soy"
ComboBox1.AddItem "vegetable"
'Use drop-down list
ComboBox1.Style = fmStyleDropDownList
'Combo box values are ListIndex values
ComboBox1.BoundColumn = 0
'Set combo box to first entry
ComboBox1.ListIndex = 0
End Sub

and here is the code that copies what they choose to ProductDatabse column G

Sheets("ProductDatabase").[g65536].End(xlUp).Offset(1, 0) = ComboBox1.Value


Hi

I am using the following code to try to populate a combox:

Private Sub ComboBox1_enter()
For Each Item In Range("Customers!S2:S6")
ComboBox1.AddItem (Item)
Next
'Combo box values are ListIndex values
ComboBox1.BoundColumn = 0
'Set combo box to first entry
ComboBox1.ListIndex = 0
End Sub

The problem is that although the combobox has 5 dropdown entries, they are all blank.

Any help much appreciated


I found the following question from last October, and it's exactly what I need an answer for. Unfortunately, it was never completed. So, with apologies to Tim C., I've just copied his question into this thread.

Quote:

Hi I have a column A from my spreadseet listed in a combobox.
I also have a list box that i would like to display a column b item depending on the clicked item in the combo box.

Here is an example:
I have partnumbers in column A
I have part descriptions in column B
So.. to set it straight, if i took partnumber from A2, then B2 would be the description to that part.

So now i have the list of partnumbers in my combobox and what want is when i select a partnumber from the dropdown list, the listbox will show me the part description. Here is what i have so far:

Private Sub UserForm_Initialize()

ComboBox1.RowSource = "'INV-A TO E'!A1:A400"
ComboBox1.Style = fmStyleDropDownList
ComboBox1.BoundColumn = 0
ComboBox1.ListIndex = 0
ListBox1.ListIndex = 0

End Sub

This gives me the a list in my combobox from A1 to A400 from a sheet called INV-A TO E.

Can someone help on this?

Thanx.

Tim C.

BTW, Tim C., if you solved this on your own, could you please enlighten me to your solution?

Thanks in advance for any and all help!


This UserForm displays values from a large worksheet. Users select a date they wish to view with the combobox. The displayed values are the totals for that date.

Suggestions on how to provide weekly or monthly totals on this UserForm.
Code:

  
 Private Sub ComboBox1_Change() 
  
 TextBox1.Value = (Format(Range("T" & ComboBox1.ListIndex + 2) + Range("U" & ComboBox1.ListIndex + 2) * 0.25, "$ #.00")) 
 TextBox2.Value = (Format(Range("V" & ComboBox1.ListIndex + 2) + Range("W" & ComboBox1.ListIndex + 2) * 0.25, "$ #.00")) 
 TextBox3.Value = (Format(Range("X" & ComboBox1.ListIndex + 2) + Range("Y" & ComboBox1.ListIndex + 2) * 0.25, "$ #.00")) 
 TextBox4.Value = (Format(Range("T" & ComboBox1.ListIndex + 2) + Range("U" & ComboBox1.ListIndex + 2) * 0.25, "$ #.00")) 
 TextBox5.Value = (Format(Range("AE" & ComboBox1.ListIndex + 2), "$ #.00")) 
 TextBox6.Value = (Format(Range("AF" & ComboBox1.ListIndex + 2), "$ #.00")) 
 TextBox7.Value = (Format(Range("AD" & ComboBox1.ListIndex + 2), "$ #.00")) 
 TextBox8.Value = (Format(Range("AG" & ComboBox1.ListIndex + 2), "$ #.00")) 
 TextBox9.Value = (Format(Range("AH2"), "$ #.00")) 
  
 End Sub 





Greetings All! Long time lurker, first time poster.

I'm trying to add a should-be-simple ActiveX combobox. I had a tough time finding a simple way of adding the combobox's cases without using a list within the active sheet or a hidden user form.

I'm using Excel 2002...

I ended up with:

Code:

Private Sub UserForm_Initialize()

ComboBox1.AddItem "Show current projects"        'ListIndex = 0
ComboBox1.AddItem "Show all projects"       'ListIndex = 1
ComboBox1.AddItem "Show summary only"          'ListIndex = 2
ComboBox1.Style = fmStyleComboBox
ComboBox1.ListIndex = 0

End Sub

Private Sub ComboBox1_Change()
   Select Case ComboBox1.Value
   Case "Show current projects"
   Range("15:17, 30:32, 43:45, 56:58, 69:71, 82:84, 95:97, 108:111, 122:124, 135:137, 148:150, 161:163, 179:181").EntireRow.Hidden = True
   Case "Show all projects"
   Rows("1:250").Hidden = False
   Case "Show summary only"
   Range("8:17, 22:32, 35:45, 48:58, 61:71, 74:84, 87:97, 100:111, 114:124, 127:137, 140:150, 153:163, 171:181").EntireRow.Hidden = True
End Select
End Sub


The combobox was blank at first. After using Debug -> Compile VBAProject in the VBA Editor menu, the three items showed up in the combobox and the code worked as expected. Yippee!

However, upon saving and reopening the file, the combobox only showed the first case in the list ("Show current projects") and clicking the dropdown button gave me a blank list in the dropdown.

I'm sure I'm missing something basic here, but for the life of me, I can't figure out what that might be!

Many thanks in advance for any light that might be shed on this odd li'l dilemma...


Hello,
I need your help, I try to populate an combobox via an text file (data.txt) but I do not know how to do it.

I put in attachment the example. any direction will be appreciated.
thx
A.
Code:

Private Sub ComboBox1_Change()
    Range("D5:H5") = Null
End Sub

Private Sub ComboBox2_Change()
    Range("D6:H6") = Null
End Sub

Private Sub CommandButton1_Click()
    With ComboBox1
            Range("D5:H5") = ComboBox1.List(.ListIndex, 1)
    End With
    With ComboBox2
            Range("D6:H6") = ComboBox2.List(.ListIndex, 1)
    End With

    
End Sub



Private Sub UserForm_Initialize()
    With ComboBox1
        .ColumnCount = 1
        .AddItem "poz1":
        .List(.ListCount - 1, 1) = "c:/data.txt"
        .List(.ListCount - 1, 2) = "c:/data.txt"
        .List(.ListCount - 1, 3) = "c:/data.txt"
        .ListIndex = 0
        .ColumnCount = 1
        .AddItem "poz2":
        .List(.ListCount - 1, 1) = ""
        .List(.ListCount - 1, 2) = ""
        .List(.ListCount - 1, 3) = ""
        '.ListIndex = 0
    End With
    With ComboBox2
        .ColumnCount = 1
        .AddItem "poz1":
        .List(.ListCount - 1, 1) = ""
        .List(.ListCount - 1, 2) = ""
        .List(.ListCount - 1, 3) = ""
        .ListIndex = 0
        .ColumnCount = 1
        .AddItem "poz2":
        .List(.ListCount - 1, 1) = "c:/data.txt"
        .List(.ListCount - 1, 2) = "111111"
        .List(.ListCount - 1, 3) = "55555555"
        '.ListIndex = 0
    End With


End Sub





I met a problem for saving the choice of the combobox, hope you can give me the help.

I used a combobox in the spreadsheet.it has mutiple choices corresponding to different values to be displayed in another raw. For the iniatialization, I used a micro "auto_open" and initialized the first choice of the list for it. The problem is how to save the change for my choice? Now it is always the first choice when I open the workbook, I hope it can be changed and saved as I want anytime. How to do it?

My code is as below:

Code:

Sub Auto_open()
With Worksheets("Plane").ComboBox1
.AddItem "A"
.AddItem "B"
.AddItem "C"
.AddItem "D"
.Style = fmStyleDropDownList
.BoundColumn = 0
.ListIndex = 0
End With
End Sub

Private Sub ComboBox1_Change()
Select Case ComboBox1.Text
Case "A"
Worksheets("Plane").Cells(9, 4).Value = Worksheets("Library").TextBox1.Value
Case "B"
Worksheets("Plane").Cells(9, 4).Value = Worksheets("Library").TextBox2.Value
Case "C"
Worksheets("Plane").Cells(9, 4).Value = Worksheets("Library").TextBox3.Value
Case "D"
Worksheets("Plane").Cells(9, 4).Value = Worksheets("Library").TextBox4.Value
End Select
End Sub


Pike,thank you very much for your modification.

In order to make the question more clear, I attached the file here.
There are 2 sheets, one is the 'library', that is the resource, the other is 'plane', that is the application.

The question is if I changed the choice for combobox in sheet 'plane'. How to keep this choice when it is opened next time. Now, it always changed to the intial value '1' when it is opened.

Looking for the solution.
[attach]


Hello,

On UserForm1 I have:

Code:

Dim i as Integer

Private Sub UserForm_Initialize()
ComboBox1.Clear
ComboBox1.AddItem ""
ComboBox1.AddItem "Item1"
ComboBox1.AddItem "Item2"
ComboBox1.AddItem "Item3"
ComboBox1.ListIndex = -1
ComboBox1.Visible = True

TextBox1.Visible = True
TextBox1.SetFocus
CommandButton1.Visible = True
End Sub

Private Sub CommandButton1_Click()
                            For i = 0 To ComboBox1.ListCount
                                If ComboBox1."?what is it?"  TextBox1.Text Then
                                    ComboBox1.AddItem Me.TextBox1.Text
                                    ComboBox1.Value = Me.TextBox1.Text
                                    ComboBox1.Visible = True
                                    Exit For
                                End If
                            Next
End Sub


When i write in TextBox1 "Item4" and click CommandButton1, I'd like to compare the value in TextBox1 with all the values in ComboBox1 and:

1) if TextBox1 value is equal to one of ComboBox1 values Then MsgBox "1"
2) if TextBox1 value is not equal to one of ComboBox1 values then add it to ComboBox1

Hlp Pls


Hi, I'm new to this forum and new to VBA, I have a small question that I need a little help with.

I'm using excel 2003.

basically what I'm trying to do is create a combobox on sheet 1 of my workbook.

the code I've used is...


Private Sub ComboBox1_DropButtonClick()
With ComboBox1
ComboBox1.AddItem "aaa"
ComboBox1.AddItem "bbb"
ComboBox1.AddItem "ccc"
End With
End Sub

this does work, but each time I click on the combo box it repeats the list over and over again for each time I clikc on the list.

hope this is making sense.

thanks for any help in advance.

regards
Sukh


Hi

Basically i've got certain cells (range) e.g. B2:D4 that i've named. I have a combo box that lists all the names... "Topic A - Topic Z". What i'm trying to do is add a row when i choose one of the topics, so if i choose Topic A, it adds a row to topic A.

How would i go about doing this?

Here's my code... if you can make sense of it.

Code:

Private Sub ComboBox1_DropButtonClick()
Do While ComboBox1.ListCount > 0
ComboBox1.RemoveItem (0)
Loop

ComboBox1.AddItem "Topic A"
ComboBox1.AddItem "Topic B"
ComboBox1.AddItem "Topic C"
ComboBox1.AddItem "Topic D"
ComboBox1.AddItem "Topic E"
ComboBox1.AddItem "Topic F"
ComboBox1.AddItem "Topic G"
ComboBox1.AddItem "Topic H"
ComboBox1.AddItem "Topic I"
ComboBox1.AddItem "Topic J"
ComboBox1.AddItem "Topic K"
ComboBox1.AddItem "Topic L"
ComboBox1.AddItem "Topic M"
ComboBox1.AddItem "Topic N"
ComboBox1.AddItem "Topic O"
ComboBox1.AddItem "Topic P"
ComboBox1.AddItem "Topic Q"
ComboBox1.AddItem "Topic R"
ComboBox1.AddItem "Topic S"
ComboBox1.AddItem "Topic T"
ComboBox1.AddItem "Topic U"
ComboBox1.AddItem "Topic V"
ComboBox1.AddItem "Topic W"
ComboBox1.AddItem "Topic X"
ComboBox1.AddItem "Topic Y"
ComboBox1.AddItem "Topic Z"
End Sub

Private Sub CommandButton3_Click()
Dim rw1 As Integer
Dim cbo As Integer


If ComboBox1.Value = "Topic A" Then
cbo = Range("TopicB").Select
    Selection.EntireRow.Insert
   End If

rw1 = cbo - 1
If rw1 = 0 Then
rw1 = 1
Else
End If

 Range(Cells(rw1, 2), Cells(rw1, 2)).Value = TextBox3.Value 



If TextBox5.Value >= 1 Then
hypx = TextBox5.Value
hypx = "\\MERLIN\DATA\GLOBAL\CDT Updates\" & hypx & ".doc"
Range(Cells(rw1, 2), Cells(rw1, 2)).Select
ActiveSheet.Hyperlinks.add Anchor:=Selection, Address:=hypx, _
        TextToDisplay:=TextBox3.Value
End If


Unload UserForm1
End Sub

Private Sub CommandButton4_Click()
Unload UserForm1
End Sub


Thanks


Hi I have a column A from my spreadseet listed in a combobox.
I also have a list box that i would like to display a column b item depending on the clicked item in the combo box.

Here is an example:
I have partnumbers in column A
I have part descriptions in column B
So.. to set it straight, if i took partnumber from A2, then B2 would be the description to that part.

So now i have the list of partnumbers in my combobox and what want is when i select a partnumber from the dropdown list, the listbox will show me the part description. Here is what i have so far:

Private Sub UserForm_Initialize()

ComboBox1.RowSource = "'INV-A TO E'!A1:A400"
ComboBox1.Style = fmStyleDropDownList
ComboBox1.BoundColumn = 0
ComboBox1.ListIndex = 0
ListBox1.ListIndex = 0

End Sub

This gives me the a list in my combobox from A1 to A400 from a sheet called INV-A TO E.

Can someone help on this?

Thanx.

Tim C.


Hi.

Using VB 6.3 within Excel 2003, I'd like to create comboboxes, but with one item already selected. I tried with:

Code:

ComboBox1.Clear
ComboBox1.AddItem "Boston"
ComboBox1.AddItem "Miami"
ComboBox1.AddItem "Washington"
ComboBox1.AddItem "Chicago"
ComboBox1.SelectedItem "Washington"


But it, obviously, does not work.

Does it exist the possibility of selecting an item after creating the combobox? Thank you very much.


good morning
I have this kind of problem:
I need to populate an table via combobox. I have two comboboxes, one is named "formula" combobox1 and will insert an formala to an range of cells.
In this formula, I have the second combobox2 that has to give me some text value: polimer1, polimer2 etc. depends on this value, MATCH() function will take an value from table polimer "this one was created via "Insert >> name ..in excel" but I received all the time error #NAME. so how can I write an correct code that will take the value from combobox2and inserted in an excel function?
also some time wen I open the excel sheet the dropdown value from combobox will not gone be displayed..I do not why.

so please can you help me?

thank you
Code:

Private Sub ComboBox1_Change()
If ComboBox1.Value = "Formula1" Then
Range("B33:J52") = "=60/INDEX(data,MATCH($A$33:$A$52,aditivi,0),MATCH(ComboBox2.text,polimeri,0))"


End If


End Sub

Private Sub ComboBox2_Change()

End Sub

Private Sub Worksheet_Activate()
ComboBox1.Clear
ComboBox1.AddItem ("Formula1")
ComboBox1.AddItem ("Formula2")
ComboBox1.AddItem ("Formula3")
ComboBox2.Clear
ComboBox2.AddItem ("polimer1")
ComboBox2.AddItem ("polimer2")
ComboBox2.AddItem ("polimer3")
End Sub