Populating Combo boxes using For...Next Loop

cutegwapings

New Member
Joined
Oct 12, 2006
Messages
47
I'm a newly registered user of MrExcel.com, and I'm glad to be here.


I just want to know how to populate combo boxes using for...next loop.

I'm using VB in excel, and I'm getting err message "Sub or Function not defined" when I tried to run the program.

Here's my code.

Private Sub Worksheet_Activate()

Dim I As Integer

For I = 1 To 5
ComboBox(I).Clear
ComboBox(I).AddItem "N/A"
ComboBox(I).AddItem "YES"
ComboBox(I).AddItem "NO"
ComboBox(I).Text = ComboBox1.List(0)
Next I

End Sub

Thank you so much!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
thanks..

Ok, I'll create a new topic next time and I'll use the search tool on this site, sorry for that.

For my question about using tab, I'm talking about the the controls that you include on excel like Text boxes. How will you go from one text box to another using the tab on the keyboard. Is it possible?

Thanks again.
 
Upvote 0
You can set the taborder

goto the VBA-menu "display" (possibly this is the wrong name in english ?, please confirm: anyway it's the third menu)
you'll see "taborder"

shortcut: rightclick userform and select "taborder"

kind regards,
Erik
 
Upvote 0
Hello again Erik,

I didn't use a userform. I just put the text boxes directly to Excel sheet. And when I used the tab, it doesn't want to go to the next text box.

Thanks again...
 
Upvote 0
add code to each textbox like this
Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyTab Then TextBox2.Activate
End Sub
if you have many of them, other code could be used

have a nice sunday,
Erik
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,998
Members
448,541
Latest member
iparraguirre89

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top