PDA

View Full Version : Solved: populate with range from another sheet



edjohns
09-20-2012, 09:20 AM
hi,

i am trying to populate a combobox in a userform with a range from a sheet, the problem is, the combobox
is filled with rows from the active sheet rather than the one i am defining.

here's the code


Sub UserForm_Activate()
Dim sheet As Worksheet
Dim defectos As Range

Set sheet = ThisWorkbook.Worksheets("VALUES")

With sheet
Set defectos = .Range(.Range("F2"), .Range("F2").End(xlDown))
End With

cbb_defectos.RowSource = defectos.Address

End Sub

it doesn't give any errors but instead of using the specified range in worksheets("values") it getsthe row source property from that range in the active worksheet (which is not what i want). i dont think
i can activate "values" sheet because this user form performs some routines on the original sheet, which is the one where its getting the row source from with this code.

thank you.

CatDaddy
09-20-2012, 09:48 AM
Sub UserForm_Activate()
Dim cell As Range

With ThisWorkbook.Worksheets("VALUES")
For Each cell In .Range(.Range("F2"), .Range("F2").End(xlDown))
cbb_defectos.AddListItem (cell.Value)
Next cell
End With

End Sub

edjohns
09-20-2012, 10:49 AM
thank you very much.

works like a charm.

CatDaddy
09-20-2012, 10:58 AM
no problem!

edjohns
09-20-2012, 12:13 PM
i used cbb_defectos.AddItem instead of AddListItem, i got an error that way