PDA

View Full Version : Useing a variable to control a combobox



Tezzies
07-22-2008, 01:25 AM
Hello all,


I have several ComboBoxs to populate and would like to try and do this using some sort of loop. Is this possible??


My code is similar to this-



Dim i as integer
Dim Temp as msforms.combobox

For i = 12 to 30

set Temp = "CbxComments" & i

Temp.additem "test1"
Temp.additem "test2"

next i



I know i could popualte the boxs seperatly but in practice I have lots of boxs to populate and would like to be box clever.

Simon Lloyd
07-22-2008, 02:32 AM
You have used a forms combobox but is it on a userform or a worksheet?

Bob Phillips
07-22-2008, 02:59 AM
Dim i As Long
Dim Temp As msforms.ComboBox

For i = 12 To 30

Set Temp = Me.Controls("CbxComments" & i)

Temp.AddItem "test1"
Temp.AddItem "test2"
Next i