Thread: Looping Problem
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Looping Problem

Todd,

Try something like the following:

Dim Rng As Range
Dim CBX As MSForms.ComboBox
Set CBX = UserForm1.Controls(Worksheets(8).Range("V1").Text)
CBX.Clear
For Each Rng In Range("NoDupes")
CBX.AddItem Rng.Text
Next Rng
UserForm1.Show



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Todd Huttenstine" wrote in message
...
Below is a code I am trying to modify.

For Each Item In NoDupes
OrderForm.ComboBox1.AddItem Item
Next Item

The above code works but is not what I need. Because the

actual ComboBox
will not always be ComboBox1, I need to make the code dynamic.

I need the
code to look in cell V1 on worksheets(8) for the value. This

value in that
cell will be the current combobox that needs to be in the code.

For
example, lets say the value in cell V1 in worksheets(8) is

"CombBox9", then
I would need for the code to reference combobox9. So how would

I write this
code?

I tried the below modification and it failed.
For Each Item In NoDupes
OrderForm.Worksheets(8).Range("V1").Value.AddItem Item
Next Item

When I ran it, I got an error that said Complie error. Method

or data
member not found.


Thanks in advance.

Todd Huttenstine