user form VBA

G

GregJG

I have a user form with combo boxes that draw the list from anothe
workbook. I use this code.

Private Sub UserForm_Initialize()
Dim wb As Workbook
Set wb = Workbooks.Open("f:\db1.xls")
For Each cell In wb.Sheets("Cust").Range("a2:A500")
Me.cboCust.AddItem cell.Value
Next cell
For Each cell In wb.Sheets("Subdiv").Range("a2:A500")
Me.cboSub.AddItem cell.Value
Next cell
wb.Close False


My problem is the .Range, instead of going to row 500, is ther
something I could do to make the list end at the last row used
regardless how long the list will becomes
 
T

Tom Ogilvy

Private Sub UserForm_Initialize()
Dim wb As Workbook
Dim rng as Range
Set wb = Workbooks.Open("f:\db1.xls")
With wb.Sheets("Cust")
set rng = .Range(.Range("A2"), .Range("A2").End(xldown))
End with
Me.cboCust.List = rng
With wb.sheets("Subdiv")
set rng = .Range(.Range("A2"),.Range("A2").End(xldown))
End With
Me.cboSub.List = rng
wb.Close False
end Sub
 
G

GregJG

Thanks for the answer, but I received an error.

"could not set the list property, Invalid property array index"

I'm gonna keep messing with it. Please post any other ideas
 
G

GregJG

Hey Tom,

I found out the problem.

Me.cboCust.List = rng

should be

Me.cboCust.List = rng.value

guessing it has something to do with office 2003

Thanks alot for your help. I wouldn't have been able to figure it ou
on my own
 
T

Tom Ogilvy

I usually do use Value in that situation (although I have seen it wor
without it), but I somehow omitted it. My bad.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top