How do i populate combobox with only part of table

Rulle

New Member
Joined
Nov 9, 2018
Messages
7
I want to populate combobox with the first 3 collums from table1 and the whole table from table2. But I also want my workbook to be dynamic, so I can move the tables around and not affect the userforms comboboxes.

So far I have populatet the comboboxes with this code:
Code:
With combobox1
    .AddItem Sheets("sheet1").Range("b74").Value
    .AddItem Sheets("sheet1").Range("b75").Value
    .AddItem Sheets("sheet1").Range("b76").Value
    .AddItem Sheets("sheet1").Range("b77").Value
End With

With tables I have tried populate the comboboxes in a lot of ways.

Like this


Code:
com_2_1.RowSource = Range("table1").Cells(3#).Address

In this way I can only add a single cell and it erases previous populatet data.

How can I populate data to combobox and not delete previous combo-data and at the same time make my references dynamic.?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Not sure I'm clear here:

You want combobox loaded with values from two different tables??

You earlier said:

I want to populate combobox with the first 3 collums from table1 and the whole table from table2

Is this A Multicolumn Combobox?

Or is the second Table only One column Wide?
 
Upvote 0
Now you could write your previous script like this:

Assuming you want to start on row 74 and go to row 100

Code:
Private Sub CommandButton1_Click()
'Modified  11/9/2018  2:48:43 AM  EST
ComboBox1.Clear
With ComboBox1
For i = 74 To 100
    .AddItem Sheets("sheet1").Cells(i, 2).Value
Next
End With
End Sub
 
Upvote 0
Now you could write your previous script like this:

Assuming you want to start on row 74 and go to row 100

Code:
Private Sub CommandButton1_Click()
'Modified  11/9/2018  2:48:43 AM  EST
ComboBox1.Clear
With ComboBox1
For i = 74 To 100
    .AddItem Sheets("sheet1").Cells(i, 2).Value
Next
End With
End Sub

Sorry for the misunderstanding.

In the above code it refers to sheet1, but if i move the table to a different sheet, the code stays the same and dosent work. I have over 100 one column tables with different uniqe names. So it is important that the code referes to a specific table, and some times specific collumns in that table.

Hope it made sence
 
Upvote 0
Your original code does not refer to a Table.

It just refers to a Range on a sheet.

Using a Table you would have to refer to it like this

Sheets(2).Listobjects("Table1")

Are you sure your talking about a excel Table or a excel Sheet.

A Table is a range on a sheet.
 
Upvote 0
Your original code does not refer to a Table.

It just refers to a Range on a sheet.

Using a Table you would have to refer to it like this

Sheets(2).Listobjects("Table1")

Are you sure your talking about a excel Table or a excel Sheet.

A Table is a range on a sheet.

I can see why you are confused.

So far i have made my references to specific cells and ranges. That is what i showed in the first code example.

But in that way my workbook got messy, so i took a deccision to make my workbook dynamic.

Now i have made all data ranges to 1 collumn named tables. And then i want to refference my comboboxes and listboxes to these tables, but cant figure out how.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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