Iterate Through OLEObjects For i

JStellato

Board Regular
Joined
Nov 6, 2010
Messages
55
I want to iterate through a range of combo boxes with similar names and add items to the combo box.

Code:
For i = 1 To 5

Set varComoBox = ThisWorkbook.Worksheets("System").OLEObjects("cbo" & i)


With varComoBox & i
.AddItem ">"
.AddItem ">="
.AddItem "<"
.AddItem "<="
.AddItem "="
End With
Next I

This code errors on the "With" with "Object does not support this property or method"

Thanks!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try replacing...

Code:
With varComoBox & i

with

Code:
With varComoBox.Object

Hope this helps!
 
Last edited:
Upvote 0
Thanks for the reply, I tried that, but it just brought the error down to the .AddItem line with the same error message.
 
Upvote 0
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG05Oct05
[COLOR="Navy"]Dim[/COLOR] I [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
[COLOR="Navy"]For[/COLOR] I = 1 To 5
    [COLOR="Navy"]With[/COLOR] ThisWorkbook.Worksheets("System").OLEObjects("ComboBox" & I).Object
        .AddItem ">"
        .AddItem ">="
        .AddItem "<"
        .AddItem "<="
        .AddItem "="
    [COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Next[/COLOR] I
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Actually, I had corrected my post so that it should be...

Code:
With varComoBox.Object
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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