Auto Editing the Row source.

  • Thread starter Thread starter countryfan_nt
  • Start date Start date
C

countryfan_nt

Hi,
I have a combobox in the userform. And I have a data range: (A2:A40).

I want the dropdown to read the range A2:A40.

That will help the user choose from the dropown list.

Now what if the range gets smaller or larger. Do I have to change the
"Row Source" Everytime a change takes place?

I mean A40 is the destination, but it might be less in the future so
how do I
fix: A2:A40 once and for all.


Thanks,
Nawaf
 
Hi,
Try this:

Private Sub UserForm_Initialize()
lr = Cells(Rows.Count, "A").End(xlUp).Row ' Last row
ComboBox1.RowSource = "a2:a" & lr
End Sub

HTH
 
Thanks,

But, When I run the code I get "Compile error: Varriable not defined".
And "lr =" is highlighted. What Am I missing? Or what did I do wrong?

Nawaf
 
Add "Dim lr as Long" to the macro as I take it you have (correctly) an
"Option explicit" statement in you code.

HTH
 
Ok 2 more questions:

1: Do I need to specify the sheet name in the code because A2 is vague
without mentioning the sheet name. The sheet name is "LookupLists".

2: Where do I place the code. I mean should it be inside the comboBox
"View Code"
 
Back
Top