error message on populating combobox
Hi Mike,
this did the trick - works beautifully, thank you!!!!
Have a very nice we
--
Valeria
"Mike H" wrote:
Hi,
With 1 entry in the list end_row ends up less then begin_row so modify your
code like this
Private Sub Userform_Initialize()
Dim End_Row As Long
Dim Begin_Row As Long
Dim i As Long
i = 0
Do
i = i + 1
Loop Until Worksheets("Data").Cells(i, 1) _
= Worksheets("Choix").Cells(4, 1)
Begin_Row = i
Do
i = i + 1
Loop Until Worksheets("Data").Cells(i, 1) _
< Worksheets("Choix").Cells(4, 1)
End_Row = i - 1
If End_Row Begin_Row Then
Me.ComboBox1.List = Worksheets("Data").Range( _
"B" & Begin_Row & ":B" & End_Row).Value
Else
Me.ComboBox1.AddItem Worksheets("Data").Range("B" & Begin_Row)
End If
End Sub
Mike
"Valeria" wrote:
Correcting what I said: sometimes I have just 1 entry in the list, and that's
when it gives the error; otherwise it works beautifully. Is there a way to
manage the 1 entry lists?
Thanks!
--
Valeria
"Valeria" wrote:
Hi Mike
thanks, for some reasons I cannot find my previous post any longer - I
thought it had not gone through!
I have tried your code, it gives me the error "Could not set the List
Property. Invalid property array index"...
Thanks,
Kind regards
--
Valeria
"Mike H" wrote:
I gave you the answer to this 3 days ago, did you try it
Private Sub Userform_Initialize()
Dim End_Row As Long
Dim Begin_Row As Long
Dim i As Long
i = 0
Do
i = i + 1
Loop Until Worksheets("Data").Cells(i, 1) _
= Worksheets("Choix").Cells(4, 1)
Begin_Row = i
Do
i = i + 1
Loop Until Worksheets("Data").Cells(i, 1) _
< Worksheets("Choix").Cells(4, 1)
End_Row = i - 1
Me.ComboBox1.List = Worksheets("Data").Range( _
"B" & Begin_Row & ":B" & End_Row).Value
End Sub
Mike
"Valeria" wrote:
Dear experts,
I need to populate a combobox in VBA with the values coming from a database,
chosen according to the input the user makes on a previous combobox. (I was
using the indirect funtion outside VBA).
However, I get an error from the code.... here it is:
Private Sub Userform_Initialize()
Dim rng As Range
Dim End_Row As Integer
Dim Begin_Row As Integer
Dim i As Integer
i = 0
Do
i = i + 1
Loop Until Worksheets("Data").Cells(i, 1) = Worksheets("Choix").Cells(4, 1)
Begin_Row = i
Do
i = i + 1
Loop Until Worksheets("Data").Cells(i, 1) < Worksheets("Choix").Cells(4, 1)
End_Row = i - 1
Set rng = Range((Worksheets("Data").Range("B", Begin_Row)),
Worksheets("Data").Range("B", End_Row))
Me.ComboBox1.List = rng.Value
End Sub
I am using Excel 2003.
Could you please help?
Many thanks!
Kind regards,
--
Valeria
|