Get values from columns with variable amount of rows to a list box in a userform?

Rob*

Board Regular
Joined
Apr 23, 2010
Messages
82
Hi.

I need som VBA help.
I have a ListBox with three columns. These columns should be filled with values from column A to C.
It's fine this far, and I can figure out how to get the values but with massive code to get values from each cell if I know how many rows I have...

Now, as the rows with values in the columns will increase or even decrease I need something that can figure out how many rows of values I have and only add these rows.
Some kind of loop that adds row by row from all three columns?

Anyone have a solution for this?
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
They all have names, and if you don't like the names you can change them.

How many listboxes are there?

Also, how did you create them?

That's quite important as the exact code you need depends on whether it's an ActiveX control or a Forms control.

How do I change the name? I've used a Form contol.
 
Upvote 0
In the top left, next to the formula bar there's the Name Box.

When you select the control that should show it's name.

If you want to change it's name then you can just enter it in the name box.
 
Upvote 0
In the top left, next to the formula bar there's the Name Box.

When you select the control that should show it's name.

If you want to change it's name then you can just enter it in the name box.

Oh, that's easy.

Now, how do I populate the listbox automatically with the code I got earlier in this thread?

Code:
LastRow =  Range("A"&Rows.Count).End(xlUp).Row   
Listbox1.List = Range("A1:C"& LastRow).Value

Can I run it from Worksheet_Activate? Someone did not recommend that. What can I do instead?
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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