User Form Control having Control Source with Dynamic Range

canesbr

New Member
Joined
Jan 5, 2004
Messages
43
I have a Userform.
It contains a ListBox and a ComboBox and a TextBox (.enable=false)

The Listbox has a control source called CaseChoice which is a static rangename =$AO$1
The TextBox has a control source of CaseChoice as well
The ComboBox has a control source named EntryItem which is a dynamic rangename =offset(ItemChoice,0,CaseChoice)
ItemChoice is a static rangename=$AO$16.

So the CaseChoice has a value of 4, say, when I load the UserForm.
The TextBox shows 4 - good
I select the third item in the listBox
The TextBox shows 3 which is good
I change the ComboBox value.
And offset(ItemChoice,0,4) gets changed - not offset(ItemChoice,0,3) - which is bad.
So it looks like the dynamic range name is not being refreshed during the time that the UserForm is Loaded and shown when the CaseChoice cell is changed.

What am I missing or doing wrong?
How do I refresh the dynamic rangename?
Regards
Brian
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hard coding your data to forms is not good if you want flexibiity. The thing to do is pass the data to the form using a property procedure, and within the procedure adding it to the control.

In the form's code module:
Code:
Property Let EntryItem(vNew As Variant)
  Me.ComboBox1.List = vNew
End Property

This code accepts a variant, which in this case is an array, and assigns it to the Combo Box's list.

In the procedure which calls the form:
Code:
  Load UserForm1
  UserForm1.EntryItem = Worksheets("Sheet1").Range("EntryItem").Value
  UserForm1.Show

This code defines the array as the values in the defined range name, and sends it off to the form, then shows the form.

I have a more detailed example on my web site:
http://peltiertech.com/Excel/PropertyProcedures.html
 
Upvote 0
Re: User Form Control having Control Source with Dynamic Ran

I have a Userform.
It contains a ListBox and a ComboBox and a TextBox (.enable=false)

The Listbox has a control source called CaseChoice which is a static rangename =$AO$1
The TextBox has a control source of CaseChoice as well
The ComboBox has a control source named EntryItem which is a dynamic rangename =offset(ItemChoice,0,CaseChoice)
ItemChoice is a static rangename=$AO$16.

So the CaseChoice has a value of 4, say, when I load the UserForm.
The TextBox shows 4 - good
I select the third item in the listBox
The TextBox shows 3 which is good
I change the ComboBox value.
And offset(ItemChoice,0,4) gets changed - not offset(ItemChoice,0,3) - which is bad.
So it looks like the dynamic range name is not being refreshed during the time that the UserForm is Loaded and shown when the CaseChoice cell is changed.

What am I missing or doing wrong?
How do I refresh the dynamic rangename?
Regards
Brian

Brian,

Not sure if I understand completely, but you can refreshed a rowsource with something like this:

combobox1.RowSource="EntryItem" when you you make a change that affects it.

Not sure if you need to reset it first to a null. I do something similar in one of my projects where I have a default rowsource. and then when a different combo box is selected that affects it I clear the rowsource and the combo box current value and then use additem. I previously was reseting the RowSource before using the additem method which I now do.

Previously I was resetting the RowSource since the dynamic rowsource would change based on the selections of the other combos which sound similar to what you need to do.

This (additem) works for me since I have a fairly limited number of entries needed after a change is made elsewhere.

For example prior to a selection change in another combo box the combo box in question is loaded with all areas. After a selection is made this number is reduced to sub areas and can easily be handled with additem.

Perry
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,282
Members
452,902
Latest member
Knuddeluff

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