Using a Dynamic Range as a "ComboBox RowSource" in VBA UserForm

ilkay

New Member
Joined
Mar 13, 2012
Messages
10
Hey everyone.
I have an excel workbook that contains two sheets (databases) and a UserForm. On the UserForm, I have a ComboBox. What I want to do is to set a dynamic range in "Sheet2" as a RowSource for the ComboBox. Actually I am able to set it, but if I am on "Sheet1" ComboBox takes its RowSource values from "Sheet1" although I defined "Sheet2" in my code. Here is the code:

Code:
Dim r As Range
With Worksheets("Sheet2")
        Set r = .Range("B2", .Range("B65536").End(xlUp))
End With

ComboBox1.RowSource = r.Address

Any help would be appreciated.
Thanks in advance.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Welcome to the board.

That's because the address property you have used doesn't qualify the sheet name. Try;

Code:
ComboBox1.RowSource = "Sheet2!" & r.Address
 
Upvote 0
I appreciate your flash help "Jon von der Heyden"!
You are a life saver. It works now. Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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