Populate userform textbox with combobox selection (multiple occurrences)

wondmand

New Member
Joined
Oct 27, 2015
Messages
8
Thanks in advance,
What I am trying to do is use a userform combobox to make a selection and populate multiple textboxes within that userform. The sheet that the values from the combobox are found in Column A. The values occur more than once. The values that are needed to populate the text boxes are found in adjacent cells. For example dog is chosen in the combobox:
Column A Column B Column C
Row 1. Dog Lab Collie
Row 2. Cat yellow Black
Row 3. Dog Shepherd Rot

textbox1 populates with Lab
Textbox2 populates with collie
Textbox 3 populates with Shepherd
Textbox4 populates with Rot
Any help would be great!
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
this will can the list ,filling a collection as it goes,
collects only valid animals,
then fills textboxes from the collection




Code:
Private Sub postItems()
Dim c As Integer
Dim vAnimal, vWord, vRowHdr
Dim col As New Collection


vAnimal = cboBox
Range("A1").Select
While ActiveCell.Value <> ""
   c = 1
   vRowHdr = ActiveCell.Offset(0, 0).Value
   If vRowHdr <> vAnimal Then
        While ActiveCell.Offset(0, c) <> ""
                 vWord = ActiveCell.Offset(0, c).Value
                 col.Add vWord
                 c = c + 1
        Wend
   End If


   ActiveCell.Offset(1, 0).Select    'next row
Wend


 'post all item in collection
For c = 1 To col.Count
   Controls("textBox" & c) = col(c)
   'Debug.Print col(c)
Next
Set col = Nothing   'clear memory
End Sub
 
Upvote 0
My apologizes I should have been much more specific,
I have 84 Textboxes that could potentially be filled based on that combobox selection with a minimum of 7 names are as follows


MSL1, MSL2 etc through MSL14
D1, D2 etc through D14
S1, S2 etc through S14
F1, F2 etc. through F14
C1, C2 etc. through C14
L1, L2 etc. through L14
P1, P2 etc. through P14

Where will I be typing the names of the textboxes in the provided code?
Additionally, the data to fill these boxes will come from Columns B-H. Will that matter?

Thanks for the quick response!
 
Upvote 0
This may also help,
Column B Data needs to be in Textboxes...MSL1 - MSL14
Column C data needs to be in textboxes...D1 - D14
Column D data needs to be in textboxes S1 - S14
Column E data needs to be in textboxes L1 - L14
Column F data needs to be in textboxes F1 - F14
Column G data needs to be in textboxes P1 - P14
Column H data needs to be in textboxes C1 - C14

Thanks.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top