Hello all,
I trying to initialize a combox with data from another sheet.
The combobox is on a userform.
The following code alone will populate the combobox with data from the active sheet, even thought it is asked to use worksheet "TEST"
By activating the sheet "TEST" it works but I'd like the userform to stay on the sheet where it was opened.
What amI doing wrong?
this is the whole code:
I trying to initialize a combox with data from another sheet.
The combobox is on a userform.
The following code alone will populate the combobox with data from the active sheet, even thought it is asked to use worksheet "TEST"
Code:
With Worksheets("TEST")
ComboBox1.RowSource = .Range("c6", .Range("C6").End(xlDown)).Address
End With
By activating the sheet "TEST" it works but I'd like the userform to stay on the sheet where it was opened.
Code:
Sheets("TEST").Activate
With Worksheets("TEST")
ComboBox1.RowSource = .Range("c6", .Range("C6").End(xlDown)).Address
End With
What amI doing wrong?
this is the whole code:
Code:
Private Sub UserForm_Initialize()
Dim lbtarget As MSForms.ListBox
Dim rngSource As Range
Set rngSource = Sheets("DATABASE").Range("E1", Sheets("DATABASE").Range("X1").End(xlDown))
Set lbtarget = Me.ListBox1
With lbtarget
.ColumnCount = 20
.ColumnWidths = "100;50;0;50;50,50,50,30,30,30,30,30,30,30,30,30,30,100,0,30"
.List = rngSource.Cells.Value
End With
ListBox1.ListIndex = 0 'Select first row on listbox
'----- INTIALIZE COMBOBOX ------
Sheets("TEST").Activate
With Worksheets("TEST")
ComboBox1.RowSource = .Range("c6", .Range("C6").End(xlDown)).Address
End With
End Sub