Hi all,
[FONT="]Is there a way to populate a TextBox on a form, to show a correct row value, by using the collection index that is being used to populate a Comboox ? I’m trying to bypass the ten column limit.<o></o>[/FONT]
[FONT="]<o> </o>[/FONT]
[FONT="]<o> </o>[/FONT]
[FONT="]On a user form:<o></o>[/FONT]
[FONT="]<o> </o>[/FONT]
[FONT="]Combobox #1 is populated from a range that had Columns A's (from “IngredientData” range) unique values passed as a collection object.<o></o>[/FONT]
[FONT="]<o> </o>[/FONT]
[FONT="]Combobox #2 is populated using Combobox #1's value to display the rows pertaining to that choice.<o></o>[/FONT]
[FONT="]<o> </o>[/FONT]
[FONT="]The remaining nine listIndex items are displayed in textboxes.<o></o>[/FONT]
[FONT="]<o> </o>[/FONT]
[FONT="]I would like to use the values in both comboboxes to bypass the additem method, and refer directly to the column in the range, using their collection row index number in order to populate a TextBox.<o></o>[/FONT]
[FONT="]Is this possible? Is there another way?<o></o>[/FONT]
<o> </o>
<o> </o>
<o> </o>
<o> </o>
Any and all comments are appreciated.
[FONT="]Is there a way to populate a TextBox on a form, to show a correct row value, by using the collection index that is being used to populate a Comboox ? I’m trying to bypass the ten column limit.<o></o>[/FONT]
[FONT="]<o> </o>[/FONT]
[FONT="]<o> </o>[/FONT]
[FONT="]On a user form:<o></o>[/FONT]
[FONT="]<o> </o>[/FONT]
[FONT="]Combobox #1 is populated from a range that had Columns A's (from “IngredientData” range) unique values passed as a collection object.<o></o>[/FONT]
[FONT="]<o> </o>[/FONT]
[FONT="]Combobox #2 is populated using Combobox #1's value to display the rows pertaining to that choice.<o></o>[/FONT]
[FONT="]<o> </o>[/FONT]
[FONT="]The remaining nine listIndex items are displayed in textboxes.<o></o>[/FONT]
[FONT="]<o> </o>[/FONT]
[FONT="]I would like to use the values in both comboboxes to bypass the additem method, and refer directly to the column in the range, using their collection row index number in order to populate a TextBox.<o></o>[/FONT]
[FONT="]Is this possible? Is there another way?<o></o>[/FONT]
<o> </o>
Rich (BB code):
<o:p></o:p>
‘setting up the collection objects<o:p></o:p>
Set myCollection = New Collection
<o:p></o:p>
On Error Resume Next
<o:p></o:p>
With Worksheets("IngredientLists")
For Each myCell In .Range("IngredientData", .Cells(.Rows.Count, "A").End(xlUp)).Cells
myCollection.Add myCell.Value, CStr(myCell.Value)
Next myCell
End With
<o:p></o:p>
On Error GoTo 0
<o:p></o:p>
For iCtr = 1 To myCollection.Count
Me.ComboBox1.AddItem myCollection.Item(iCtr)
Next iCtr<o:p></o:p>
Rich (BB code):
<o:p></o:p>
‘initializing the boxes<o:p></o:p>
Set myCollection = New Collection
<o:p></o:p>
On Error Resume Next
<o:p></o:p>
With Worksheets("IngredientLists")
For Each myCell In .Range("IngredientData", .Cells(.Rows.Count, "A").End(xlUp)).Cells
myCollection.Add myCell.Value, CStr(myCell.Value)
Next myCell
End With
<o:p></o:p>
On Error GoTo 0
<o:p></o:p>
For iCtr = 1 To myCollection.Count
Me.ComboBox1.AddItem myCollection.Item(iCtr)
Next iCtr
<o:p></o:p>
End Sub<o:p></o:p>
Rich (BB code):
<o:p></o:p>
‘Passing the values to the Text Boxes<o:p></o:p>
Private Sub ComboBox2_Change()
<o:p></o:p>
With Me.ComboBox2
If .ListIndex < 0 Then
Exit Sub
End If
<o:p> </o:p>
Me.PU_txt.Value = .List(.ListIndex, 1)
‘yada,yada….<o:p></o:p>
Me.UnitCost_txt.Value = .List(.ListIndex, 9)
'Me.LastUpdate_txt.Value = .List(.ListIndex, 10) Can't have 11 cloumns
'Me.ConvOrganic_txt.Value = .List(.ListIndex, 11) Can't have 12 cloumns
Any and all comments are appreciated.
Last edited: