Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Looping Problem

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Looping Problem

Below is the modified code. The original is from John Walkenbach site.
When I run this code I get errors and I cant figure out whats wrong. It
also doesnt like the CBX part. Can anyone see whats wrong with it?


Sub RemoveDuplicates()
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection
Dim i As Integer, j As Integer
Dim Swap1, Swap2, Item

' The items are in A1:A105
' Modified code to be dynamic. The items for each product are in various
ranges so therefore static would not work.
' Each "Brand" field of each product has a code in the click event to put
new range in cell Y1. The below code references
' cell Y1 for the value.
Set AllCells = Worksheets(8).Range("Y1")

' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
For Each Cell In AllCells
NoDupes.Add Cell.Value, CStr(Cell.Value)
' Note: the 2nd argument (key) for the Add method must be a string
Next Cell

' Resume normal error handling
On Error GoTo 0

' Update the labels on UserForm1
' Modified this code to look at object on Userform OrderForm
' Commented out the below code because I am not using labels for status
update.
' With OrderForm
' .Label1.Caption = "Total Items: " & AllCells.Count
' .Label2.Caption = "Unique Items: " & NoDupes.Count
' End With

' Sort the collection (optional)
For i = 1 To NoDupes.Count - 1
For j = i + 1 To NoDupes.Count
If NoDupes(i) NoDupes(j) Then
Swap1 = NoDupes(i)
Swap2 = NoDupes(j)
NoDupes.Add Swap1, befo=j
NoDupes.Add Swap2, befo=i
NoDupes.Remove i + 1
NoDupes.Remove j + 1
End If
Next j
Next i


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


' Add the sorted, non-duplicated items to a ListBox
' For Each Item In NoDupes
' OrderForm.ListBox1.AddItem Item
' Next Item

' Show the UserForm
'UserForm1.Show
End Sub



"Chip Pearson" wrote in message
...
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






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Looping Problem

Todd,

It isn't clear what you are asking for. Do you want to load the
items from the collection in to a combobox? Is the combobox on a
userform? My reply was for assigning the combobox (on a
userform) dynamically at run time. Perhaps you could describe
what you are trying to accomplish.


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


"Todd Huttenstine" wrote in message
...
Below is the modified code. The original is from John

Walkenbach site.
When I run this code I get errors and I cant figure out whats

wrong. It
also doesnt like the CBX part. Can anyone see whats wrong with

it?


Sub RemoveDuplicates()
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection
Dim i As Integer, j As Integer
Dim Swap1, Swap2, Item

' The items are in A1:A105
' Modified code to be dynamic. The items for each product

are in various
ranges so therefore static would not work.
' Each "Brand" field of each product has a code in the click

event to put
new range in cell Y1. The below code references
' cell Y1 for the value.
Set AllCells = Worksheets(8).Range("Y1")

' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
For Each Cell In AllCells
NoDupes.Add Cell.Value, CStr(Cell.Value)
' Note: the 2nd argument (key) for the Add method must be

a string
Next Cell

' Resume normal error handling
On Error GoTo 0

' Update the labels on UserForm1
' Modified this code to look at object on Userform OrderForm
' Commented out the below code because I am not using labels

for status
update.
' With OrderForm
' .Label1.Caption = "Total Items: " & AllCells.Count
' .Label2.Caption = "Unique Items: " & NoDupes.Count
' End With

' Sort the collection (optional)
For i = 1 To NoDupes.Count - 1
For j = i + 1 To NoDupes.Count
If NoDupes(i) NoDupes(j) Then
Swap1 = NoDupes(i)
Swap2 = NoDupes(j)
NoDupes.Add Swap1, befo=j
NoDupes.Add Swap2, befo=i
NoDupes.Remove i + 1
NoDupes.Remove j + 1
End If
Next j
Next i


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


' Add the sorted, non-duplicated items to a ListBox
' For Each Item In NoDupes
' OrderForm.ListBox1.AddItem Item
' Next Item

' Show the UserForm
'UserForm1.Show
End Sub



"Chip Pearson" wrote in message
...
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








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Looping Problem

Sorry for not being specific. You guys are smart, but not psychic. :-) I
have 1 large userform. I have 22 products and for each product there are 3
comboboxes and 6 textboxes. All comboboxes and textboxes populate with data
that is in specific ranges on worksheets(8) of my workbook The first
combobox is the product combobox which contains the name of the product. I
select the name of the product from this box and when I do, all the other
comboboxes/textboxes associated with that product auto-populate based on a
code in the combobox change event. One of those comboboxes that populates
based on the name of the product is for the brand. For instance, lets say I
go to the product combobox that contains the product MEMORY. I select
"256MB DDR MEMORY" from this combobox. Another combobox associated with
this product is for brand. In this combobox I can select the brand of the
MEMORY I want. Here is where the problem comes in... Remember I said
earlier that the data is being pulled from ranges on worksheets(8). Well
heres how it is setup. In this instance all the memory is in Range
AS4:AS100. The Brand is in Range AT4:AT100. For each memory I have the
brand. There are many instances in which the same brand name is in Range
AS4:AS100. Because the brand combobox pulls from Range AS4:AS100, it lists
the same brand name over and over and this is what I am trying to prevent.
Now I have created a module (module6) and put the following code in it
(trying to remove these duplicates but I keep getting errors.):
Also in the click event of each brand combobox for every product, I have put
a code to put the range of where the brand names are located on
worksheets(8) in cell Y1 on worksheets(8). This is what I need the AllCells
variable to be set to. This is the only way I can make the code static and
have it reference the active brand range because the range the code needs to
look in will change based on what brand combobox is selected.


Sub RemoveDuplicates()
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection
Dim i As Integer, j As Integer
Dim Swap1, Swap2, Item

' The items are in A1:A105
' Modified code to be dynamic. The items for each product are in various
ranges so therefore static would not work.
' Each "Brand" field of each product has a code in the click event to put
new range in cell Y1. The below code references
' cell Y1 for the value.
Set AllCells = Worksheets(8).Range("Y1")

' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
For Each Cell In AllCells
NoDupes.Add Cell.Value, CStr(Cell.Value)
' Note: the 2nd argument (key) for the Add method must be a string
Next Cell

' Resume normal error handling
On Error GoTo 0

' Update the labels on UserForm1
' Modified this code to look at object on Userform OrderForm
' Commented out the below code because I am not using labels for status
update.
' With OrderForm
' .Label1.Caption = "Total Items: " & AllCells.Count
' .Label2.Caption = "Unique Items: " & NoDupes.Count
' End With

' Sort the collection (optional)
For i = 1 To NoDupes.Count - 1
For j = i + 1 To NoDupes.Count
If NoDupes(i) NoDupes(j) Then
Swap1 = NoDupes(i)
Swap2 = NoDupes(j)
NoDupes.Add Swap1, befo=j
NoDupes.Add Swap2, befo=i
NoDupes.Remove i + 1
NoDupes.Remove j + 1
End If
Next j
Next i


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


' Add the sorted, non-duplicated items to a ListBox
' For Each Item In NoDupes
' OrderForm.ListBox1.AddItem Item
' Next Item

' Show the UserForm
'UserForm1.Show
End Sub





"Chip Pearson" wrote in message
...
Todd,

It isn't clear what you are asking for. Do you want to load the
items from the collection in to a combobox? Is the combobox on a
userform? My reply was for assigning the combobox (on a
userform) dynamically at run time. Perhaps you could describe
what you are trying to accomplish.


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


"Todd Huttenstine" wrote in message
...
Below is the modified code. The original is from John

Walkenbach site.
When I run this code I get errors and I cant figure out whats

wrong. It
also doesnt like the CBX part. Can anyone see whats wrong with

it?


Sub RemoveDuplicates()
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection
Dim i As Integer, j As Integer
Dim Swap1, Swap2, Item

' The items are in A1:A105
' Modified code to be dynamic. The items for each product

are in various
ranges so therefore static would not work.
' Each "Brand" field of each product has a code in the click

event to put
new range in cell Y1. The below code references
' cell Y1 for the value.
Set AllCells = Worksheets(8).Range("Y1")

' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
For Each Cell In AllCells
NoDupes.Add Cell.Value, CStr(Cell.Value)
' Note: the 2nd argument (key) for the Add method must be

a string
Next Cell

' Resume normal error handling
On Error GoTo 0

' Update the labels on UserForm1
' Modified this code to look at object on Userform OrderForm
' Commented out the below code because I am not using labels

for status
update.
' With OrderForm
' .Label1.Caption = "Total Items: " & AllCells.Count
' .Label2.Caption = "Unique Items: " & NoDupes.Count
' End With

' Sort the collection (optional)
For i = 1 To NoDupes.Count - 1
For j = i + 1 To NoDupes.Count
If NoDupes(i) NoDupes(j) Then
Swap1 = NoDupes(i)
Swap2 = NoDupes(j)
NoDupes.Add Swap1, befo=j
NoDupes.Add Swap2, befo=i
NoDupes.Remove i + 1
NoDupes.Remove j + 1
End If
Next j
Next i


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


' Add the sorted, non-duplicated items to a ListBox
' For Each Item In NoDupes
' OrderForm.ListBox1.AddItem Item
' Next Item

' Show the UserForm
'UserForm1.Show
End Sub



"Chip Pearson" wrote in message
...
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












  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Looping Problem

Sub RemoveDuplicates()
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection
Dim i As Integer, j As Integer
Dim Swap1, Swap2, Item

' The items are in A1:A105
' Modified code to be dynamic. The items for each product are in various
ranges so therefore static would not work.
' Each "Brand" field of each product has a code in the click event to put
new range in cell Y1. The below code references
' cell Y1 for the value.
Set AllCells = worksheets(8).Range(Worksheets(8).Range("Y1").Valu e)

' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
For Each Cell In AllCells
NoDupes.Add Cell.Value, CStr(Cell.Value)
' Note: the 2nd argument (key) for the Add method must be a string
Next Cell

' Resume normal error handling
On Error GoTo 0

' Update the labels on UserForm1
' Modified this code to look at object on Userform OrderForm
' Commented out the below code because I am not using labels for status
update.
' With OrderForm
' .Label1.Caption = "Total Items: " & AllCells.Count
' .Label2.Caption = "Unique Items: " & NoDupes.Count
' End With

' Sort the collection (optional)
For i = 1 To NoDupes.Count - 1
For j = i + 1 To NoDupes.Count
If NoDupes(i) NoDupes(j) Then
Swap1 = NoDupes(i)
Swap2 = NoDupes(j)
NoDupes.Add Swap1, befo=j
NoDupes.Add Swap2, befo=i
NoDupes.Remove i + 1
NoDupes.Remove j + 1
End If
Next j
Next i

' Add the sorted, non-duplicated items to the listbox
' specified in V1 of Sheet 8.

Dim Rng As Variant
Dim CBX As MSForms.ComboBox
Set CBX = worksheets("OrderForm"). _
OleObjects(Worksheets(8).Range("V1").Text).Object
CBX.Clear
For Each Rng In NoDupes
CBX.AddItem Rng
Next Rng
End Sub



Todd Huttenstine wrote in message
...
Sorry for not being specific. You guys are smart, but not psychic. :-)

I
have 1 large userform. I have 22 products and for each product there are

3
comboboxes and 6 textboxes. All comboboxes and textboxes populate with

data
that is in specific ranges on worksheets(8) of my workbook The first
combobox is the product combobox which contains the name of the product.

I
select the name of the product from this box and when I do, all the other
comboboxes/textboxes associated with that product auto-populate based on a
code in the combobox change event. One of those comboboxes that populates
based on the name of the product is for the brand. For instance, lets say

I
go to the product combobox that contains the product MEMORY. I select
"256MB DDR MEMORY" from this combobox. Another combobox associated with
this product is for brand. In this combobox I can select the brand of the
MEMORY I want. Here is where the problem comes in... Remember I said
earlier that the data is being pulled from ranges on worksheets(8). Well
heres how it is setup. In this instance all the memory is in Range
AS4:AS100. The Brand is in Range AT4:AT100. For each memory I have the
brand. There are many instances in which the same brand name is in Range
AS4:AS100. Because the brand combobox pulls from Range AS4:AS100, it

lists
the same brand name over and over and this is what I am trying to prevent.
Now I have created a module (module6) and put the following code in it
(trying to remove these duplicates but I keep getting errors.):
Also in the click event of each brand combobox for every product, I have

put
a code to put the range of where the brand names are located on
worksheets(8) in cell Y1 on worksheets(8). This is what I need the

AllCells
variable to be set to. This is the only way I can make the code static

and
have it reference the active brand range because the range the code needs

to
look in will change based on what brand combobox is selected.


Sub RemoveDuplicates()
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection
Dim i As Integer, j As Integer
Dim Swap1, Swap2, Item

' The items are in A1:A105
' Modified code to be dynamic. The items for each product are in

various
ranges so therefore static would not work.
' Each "Brand" field of each product has a code in the click event to

put
new range in cell Y1. The below code references
' cell Y1 for the value.
Set AllCells = Worksheets(8).Range("Y1")

' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
For Each Cell In AllCells
NoDupes.Add Cell.Value, CStr(Cell.Value)
' Note: the 2nd argument (key) for the Add method must be a string
Next Cell

' Resume normal error handling
On Error GoTo 0

' Update the labels on UserForm1
' Modified this code to look at object on Userform OrderForm
' Commented out the below code because I am not using labels for status
update.
' With OrderForm
' .Label1.Caption = "Total Items: " & AllCells.Count
' .Label2.Caption = "Unique Items: " & NoDupes.Count
' End With

' Sort the collection (optional)
For i = 1 To NoDupes.Count - 1
For j = i + 1 To NoDupes.Count
If NoDupes(i) NoDupes(j) Then
Swap1 = NoDupes(i)
Swap2 = NoDupes(j)
NoDupes.Add Swap1, befo=j
NoDupes.Add Swap2, befo=i
NoDupes.Remove i + 1
NoDupes.Remove j + 1
End If
Next j
Next i


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


' Add the sorted, non-duplicated items to a ListBox
' For Each Item In NoDupes
' OrderForm.ListBox1.AddItem Item
' Next Item

' Show the UserForm
'UserForm1.Show
End Sub





"Chip Pearson" wrote in message
...
Todd,

It isn't clear what you are asking for. Do you want to load the
items from the collection in to a combobox? Is the combobox on a
userform? My reply was for assigning the combobox (on a
userform) dynamically at run time. Perhaps you could describe
what you are trying to accomplish.


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


"Todd Huttenstine" wrote in message
...
Below is the modified code. The original is from John

Walkenbach site.
When I run this code I get errors and I cant figure out whats

wrong. It
also doesnt like the CBX part. Can anyone see whats wrong with

it?


Sub RemoveDuplicates()
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection
Dim i As Integer, j As Integer
Dim Swap1, Swap2, Item

' The items are in A1:A105
' Modified code to be dynamic. The items for each product

are in various
ranges so therefore static would not work.
' Each "Brand" field of each product has a code in the click

event to put
new range in cell Y1. The below code references
' cell Y1 for the value.
Set AllCells = Worksheets(8).Range("Y1")

' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
For Each Cell In AllCells
NoDupes.Add Cell.Value, CStr(Cell.Value)
' Note: the 2nd argument (key) for the Add method must be

a string
Next Cell

' Resume normal error handling
On Error GoTo 0

' Update the labels on UserForm1
' Modified this code to look at object on Userform OrderForm
' Commented out the below code because I am not using labels

for status
update.
' With OrderForm
' .Label1.Caption = "Total Items: " & AllCells.Count
' .Label2.Caption = "Unique Items: " & NoDupes.Count
' End With

' Sort the collection (optional)
For i = 1 To NoDupes.Count - 1
For j = i + 1 To NoDupes.Count
If NoDupes(i) NoDupes(j) Then
Swap1 = NoDupes(i)
Swap2 = NoDupes(j)
NoDupes.Add Swap1, befo=j
NoDupes.Add Swap2, befo=i
NoDupes.Remove i + 1
NoDupes.Remove j + 1
End If
Next j
Next i


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


' Add the sorted, non-duplicated items to a ListBox
' For Each Item In NoDupes
' OrderForm.ListBox1.AddItem Item
' Next Item

' Show the UserForm
'UserForm1.Show
End Sub



"Chip Pearson" wrote in message
...
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












Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scrolling Looping Problem Nick Wakeham Excel Discussion (Misc queries) 0 June 12th 07 01:42 PM
Macro looping problem. [email protected] Excel Discussion (Misc queries) 8 October 26th 06 02:44 PM
Looping [email protected] Excel Programming 0 October 31st 03 07:47 PM
looping formula - r1c1 problem - Con't MDC[_2_] Excel Programming 0 October 22nd 03 11:42 PM
looping formula - r1c1 problem MDC[_2_] Excel Programming 2 October 22nd 03 11:13 PM


All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"