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!
 
Thanks for all your help!

This forum is very helpful. Response is quick. Even simple and dumb questions are answered in a friendly manner.

Thanks erik.van.geit


I would like to buy a VBA excel book, which one do you recommend?


Thanks!
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Another question

FORMULA:

If Repnames.Text = Sheets("Audit Summary").Range("B5:B80").Text Then
MsgBox "This tech has been audited, go to Audit Summary tab and delete the record first.", vbOKOnly
Exit Sub


Note: Repnames is a combo box.

I want the program to compare the name chosen from the combo box and compare it to the data already saved on the other sheet named "audit summary" to avoid data redundancy.

What's the correct formula? I'm not getting any error message but the MSGBOX is not appearing.

Thanks!
 
Upvote 0
is this a merged cell: B5:B80 ?
insert a line:
Code:
MsgBox Sheets("Audit Summary").Range("B5:B80").Text
to clarify for yourself what the text in the cells reads

any help with this ?
 
Upvote 0
Thanks again for your reply erik.

The data on those cells were not merged. Those are the list of names from B5 to B80.

I have a seperate program on another sheet named "extractor". There's a combobox named "repnames" on the "extractor" sheet where you have to choose one of the names.

When I run the program in "extractor" it will paste the data on the "audit summary" sheet. What I would like to happen is for the program to look at the list of names from B5 to B80 on the "audit summary" sheet and compare it to the name that's inputed on the "repnames" combo box from the "extractor" sheet.

A message should appear and say "The name you're trying to save is already on the database."

Thanks again for your help friend...
 
Upvote 0
look at the list of names from B5 to B80 on the "audit summary" sheet and compare it to the name that's inputed
you can use FIND
the helpfiles are very good

Sheets("Audit Summary").Range("B5:B80").Find(Repnames.Text, ... see the other arguments in the helpfiles
CAVEAT: when using FIND it is recommended to fill in all relevant arguments: if you don't Excel will remember the settings from your previous FIND, be it manually or by code: this would leave you with unexpected results
 
Upvote 0
hello again..

Thanks for all your help erik. It seems like you're the only one who's willing to help me here, thanks for that... ;)

I tried to learn on my own but I'm really a novice on programming. I wasn't still able to solve my last question.

I'd really appreciate if you could give me the exact code on how to use find.


Thanks!
 
Upvote 0
Hi -
try ( untested )
Code:
Sub sample()
With Sheets("audit summary").Range("b5:b80")
    Set c = .Find(Sheets("extractor").repnames.Text, , , xlWhole)
        If Not c Is Nothing Then
            MsgBox "This tech has been audited, go to Audit Summary tab and delete the record first.", vbCritical + vbOKOnly, "repnames already exists"
        End If
End With
End Sub
 
Upvote 0
Re: hello again..

Thanks for all your help erik. It seems like you're the only one who's willing to help me here, thanks for that... ;)

I tried to learn on my own but I'm really a novice on programming. I wasn't still able to solve my last question.

I'd really appreciate if you could give me the exact code on how to use find.
I can not agree with your first remark. There are a lot of people willing to help here.
for example agihcam :)

I understand you are a novice: we have all been there. When trying to use code, "play" with it. This means:
1. forget your own project
2. replicate the code from the helpfiles
3. execute it
4. read the documentation
5. change some arguments, sheetnames, .... (this is the real PLAYING :) )
6. only then go back to your project and will look a lot easier
 
Upvote 0
hello again...

Alright... THanks! ;)

Is there a way to enable the use of tab in excel? So that the user won't use the mouse to click on every fields?
 
Upvote 0

Forum statistics

Threads
1,215,721
Messages
6,126,456
Members
449,314
Latest member
MrSabo83

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