Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Dynamically assign ComboBox.List from named range areas

Hi guys

I would like to assign a list of values for a ComboBox. I have a named
range of various columns and based on the selection in another
ComboBox, I would like to select the relevant Area of the named range.


The code looks like this:
iBrand = cboBrands.ListIndex + 1
cboProducts.List = Range("AllBrands").Areas(iBrand).Cells.Value

The error message I receive is:
Run-time error '381': Could not set the List property. Invalid
property array index.

This seems very strange as I feel I have thoroughly debugged. I have
ascertained the validity of Range("AllBrands"), iBrand, etc.

Any suggestions appreciated.

Paul Martin
Melbourne, Australia

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Dynamically assign ComboBox.List from named range areas

The .List property is for referencing a specific element in the list, and the
syntax is
object.List( row, column ) [= Variant]
row Required. An integer with a range from 0 to one less than the number of
entries in the list.
column Required. An integer with a range from 0 to one less than the number
of columns.
Variant Optional. The contents of the specified entry in the ListBox or
ComboBox.

The error message is because you are not specifying row and column. If you
want to use the .List property to create the Combobox's list of choices you
will need to step through the rows (and columns? if you need them) to fill
the list; or alternatively use the .AddItem method (easier for a one column
list):

Dim ListFillRange as Range, ListCell as Range
Set ListFillRange = Range("AllBrands").Areas(iBrand)
cboProducts.Clear
For each ListCell in ListFillRange.Cells
cboProducts.AddItem ListCell.Value
Next ListCell

--
- K Dales


"Paul Martin" wrote:

Hi guys

I would like to assign a list of values for a ComboBox. I have a named
range of various columns and based on the selection in another
ComboBox, I would like to select the relevant Area of the named range.


The code looks like this:
iBrand = cboBrands.ListIndex + 1
cboProducts.List = Range("AllBrands").Areas(iBrand).Cells.Value

The error message I receive is:
Run-time error '381': Could not set the List property. Invalid
property array index.

This seems very strange as I feel I have thoroughly debugged. I have
ascertained the validity of Range("AllBrands"), iBrand, etc.

Any suggestions appreciated.

Paul Martin
Melbourne, Australia


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Dynamically assign ComboBox.List from named range areas

Thanks for the reply, but List can be assigned as documented on MS KB
<http://support.microsoft.com/default.aspx?scid=kb;en-us;161598
ListBox1.List = Array("One", "Two", "Three", "Four")

Regards

Paul Martin
Melbourne, Australia

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Dynamically assign ComboBox.List from named range areas

My apologies, you are quite right.

The only thing I can think that might cause the problem is if you have some
other property of the combobox set that keeps you from updating the list.
For example, if I set the RowSource property and then try to programatically
set the .List to a range of values I get the error message "Permission
Denied" (Win XP, Excel 2002).

The only other suggestion, if you have not done so already,is to be sure
cboProducts is assigned as a Combobox explicitly, not a generic Dim
cboProducts as object. Sometimes that can make a difference.
--
- K Dales


"Paul Martin" wrote:

Thanks for the reply, but List can be assigned as documented on MS KB
<http://support.microsoft.com/default.aspx?scid=kb;en-us;161598
ListBox1.List = Array("One", "Two", "Three", "Four")

Regards

Paul Martin
Melbourne, Australia


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Dynamically assign ComboBox.List from named range areas

I don't have any other properties set that conflict (already checked
that). cboProducts is a ComboBox object painted on a UserForm so no
problem with declaration either. Thanks anyway.

Regards

Paul Martin
Melbourne, Australia

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically Named Range and IsError() Stephen Lloyd[_2_] Excel Worksheet Functions 5 January 21st 09 06:36 PM
Add a data series dynamically to a named range? Popeye Charts and Charting in Excel 3 March 10th 06 08:59 PM
How to dynamically reference a dynamic named range paris3 Excel Worksheet Functions 4 June 24th 05 01:22 AM
Dynamically assign items to a list box Fernando Ronci Excel Programming 6 August 12th 04 03:18 AM
Dynamically assign items to a list box Fernando Ronci Excel Programming 0 August 11th 04 02:42 AM


All times are GMT +1. The time now is 01:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"