Select Dynamic list for rowsource on a list box

N

Nigel

I have a form which is getting values in a list box from a range on a sheet
called Customer. THe length of that list can vary depending on other
selections, it may be from A5 to A500 or A5 to A120. How can I set up the
rowsource to automatically adjust tothe correct range. (it will always start
in Cell A5


thanks
 
G

Gary Keramidas

try something like this:

Private Sub UserForm_Initialize()
Dim ws As Worksheet
Dim lastrow As Long

Set ws = Worksheets("Sheet1")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row

With Me.ListBox1
.RowSource = ws.Range("A5:A" & lastrow).Address
End With
End Sub
 
P

Paulo

PERHAPS

you could do the dynamic part on the list name.

instert>name>Define > Place this formula on the source
=offset( A5,0,0,conta(A:A),1)

A5 = your starting Cell
conta(A:A) = number of rows that have values "remenber to not have any
empty spaces on this column"
1= width "you could do a conta here as well"
 

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