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!
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
on this baord we "try" to stay on topic, this would be another question ...
but since you're new some tips

1. use the search-feature on top of the page
2. or http://www.google.com/advanced_search?q=site:MrExcel.com

your question
unlock the cells which you want to tab (see menu Format, cellproperties, last tab)
protect your sheet (menu Tools, security)

best regards,
Erik
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

cutegwapings

New Member
Joined
Oct 12, 2006
Messages
47
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.
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
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
 

cutegwapings

New Member
Joined
Oct 12, 2006
Messages
47
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...
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
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
 

Forum statistics

Threads
1,144,282
Messages
5,723,474
Members
422,499
Latest member
think say

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
Top