I have a combobox that is on a userform that I would like to populate with a list of values.
The values are in the middle of a series of columns and can be thought of as column headers as each is in its own column. The list of columns will expand over time and should be updated each time the user form is initialized. I have been able to create a list from a single column and I can also create a list from multiple columns but when I do, the values remain in a column orientation and I can't get them to transpose into a list of rows. The data in the columns looks like this:
|--|--A--+--B--+--C--+--D--+ ... +
|--|-----+-----+-----+-----+
|1 | | | | |
|--|-----+-----+-----+-----+
|2 | << other data here >>|
|--| +-----+-----+-----+
|3 | " | a | b | c | ... <~~ row 3 data (needed as 2nd element in combobox)
|--| +-----+-----+-----+
|4 | " | d | e | f | ... <~~ row 4 data (needed as 1st element in combobox)
|--| +-----+-----+-----+
|5 | " | 1 | 2 | 3 |
|--| +-----+-----+-----+
|6 | " | 4 | 5 | 6 |
|--|-----+-----+-----+-----+
|7 | " | 7 | 8 | 9 |
|--|-----+-----+-----+-----+
I want the combobox list entries to appear like this:
d a
e b
f c
This userform is initialized by another userform which selects from several options and then activates the correct worksheet from several worksheets that have similar information. When the second userform initializes, it should populate the combobox with the data in the example above. I created a list of values from a single column using:
Private Sub UserForm_Initialize()
'ReferenceCombo.ColumnCount = 2
'Range("B4", Range("B" & Rows.Count).End(xlUp)).Name = "Dynamic"
'Me.ReferenceCombo.RowSource = "Dynamic"
End Sub
I can also get a list of all values in a row using:
Dim sht As Worksheet
Set sht = ActiveSheet
ReferenceCombo.ColumnCount = 2
sht.Range(Sheet7.Cells(4, 2), Sheet7.Cells(4, Columns.Count).End(xlToLeft)).Name = "Dynamic"
sht.Range(Sheet7.Cells(4, 2), Sheet7.Cells(4, Columns.Count).End(xlToLeft)).Select
Me.ReferenceCombo.RowSource = "Dynamic"
but this only selects one of the two rows I want and doesn't transpose the list of values into the correct format.
I've tried Information from here but this does not seem to apply to userforms. Information here was helpful in selecting the row correctly. This was helpful in selecting a dynamic field. Here I found information on transposing a list but I'm not sure I understood it completely. This relates to a listfill range but I'm not sure this applies to comboboxes on userforms either. This relates to inserting a transpose function but it didn't work for me.
Any help would be greatly appreciated.