dynamic combobox
Hi John
It looks like the post you found was referring to creating a dynamic
named range, probably for a data validation list.
This would work by creating a named range using:
=OFFSET(category!$A$1,0,0,COUNTA(category!$A:$A),1 ) < note minor change
in the Refers To field. Assuming your named range is called MyRange you
could then select a cell and use DataValidation. Allow List, Source
=MyRange. This would give you a drop down in the cell which would
dynamically increase according to the data in column A.
To populate a combobox dynamically you could loop through the the
contents of column A and add items to the combobox. This example assumes
headings so starts in row 2:
Dim i As Long
For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
Me.ComboBox1.AddItem Cells(i, 1).Value
Next i
Hope this helps
Rowan
john_t_h wrote:
I have a worksheet that lists a number of categories to populate a
comobobox
Code:
--------------------
category.List = Worksheets("category").Range("A2:A10").Value
--------------------
This works great, however I want to be able to vary the number of rows
listed here and have the combobox display the rows dynamicly.
I searched through the forums and found a post that looked like the
answer.
Code:
--------------------
catRange = OFFSET(category!$A$1,0,0,COUNTA(category!$A:$A,1))
--------------------
Unfortunatley I get a compile error "Invalid character" at the first
*$*
What does this mean?
Am I on the right track?
I'm using Office 97 if that makes a difference.
|