View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
FSt1 FSt1 is offline
external usenet poster
 
Posts: 3,942
Default ComboBox RowSource Dynamic

hi
something like this might work. I tested on a sheet list box which uses
listfillrange.
a forms listbox uses row source so change that in the code. i also used
generic sheet names (just for test) it should work for the forms also. you
may have to tweek it some since i did you a sheet listbox but the basic
sentax is there.

Sub testlist()
Dim lr As Long
Dim r As Range
'find last row on other sheet
lr = Sheets("sheet2").Cells(Rows.Count, "A").End(xlUp).Row
'set the range
Set r = Range("A2:A" & lr)
'set the listfillrange(rowsource)
Sheet1.ListBox1.ListFillRange = "Sheet2!" & r.Address

End Sub

regards
FSt1

"CAMoore" wrote:

Scenerio:

I have a workbook with 2 worksheets: Main and Filenmames. On the Main
worksheet I have 2 Command Buttons and 1 ComboBox. Behind one command button
("Refresh Parts List and Create Hyperlinks") is code to search a directory of
jpg files and fill column A in the Filenames worksheet with those filenames.
Then in column B of the same Filenames worksheet, hyperlinks are created for
each of the filenames. So, basically, this button just refreshes the
filenames list and hyperlinks.

The second command button ("List Parts") displays a form with a ListBox of
the part numbers. However, I can populate the ListBox if I use the RowSource
Properies, but I have to manually type in "Filenames!B1:B2588". I dont want
to do it this way because the rows in the Filenames worksheet may be
different as new part jpg files are added.

So, my question is: How do I use VBA to define the dynamic variable
RowSource property?

Thank you for your help.

--
Other programming languages I''ve used a Cobol, C++, Informix Database,
and Unix.