Initialize Combobox without Activating Sheet

mucah!t

Well-known Member
Joined
Jun 27, 2009
Messages
593
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"
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
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
You are passing a string, but the address string does not include the sheet name. Either use:
Code:
With Worksheets("TEST")
ComboBox1.RowSource = "TEST!" & .Range("c6", .Range("C6").End(xlDown)).Address
End With

or I prefer:
Code:
With Worksheets("TEST")
ComboBox1.List = .Range("c6", .Range("C6").End(xlDown)).Value
End With

and don't use the RowSource at all.
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,152
Members
452,891
Latest member
JUSTOUTOFMYREACH

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