Populating a ListBox

  • Thread starter Thread starter ToddG
  • Start date Start date
T

ToddG

I'm sure this is probably pretty simple, but how do I
populate a ListBox with only the populated cells in a
worksheet?

For example:

Column A Column B Column C Column D
2.3 45 23.98 43.981
90 45.877 32.2 3

The ListBox would show all of these numbers using the
first row as column headers. The number of rows is
different everytime, that's why I can't just specify a
range within the ListBox.

Any help would be appreciated
 
It will take a bit of coding to do it, but here is the
approach to take.

First you need to identify the size of the range. It must
have a known start point say A3 assign a row vaiable based
on activecell.row. Use Activesheet.range("A65536").select
to go to the bottom of the sheet. Then Selection.End
(xlup).select to find the bottom of the list of data.
Then use a=activecell.row to assign the row number to a
variable a.

Now you know the start row as 4, and the bottom row as the
value in a. The number of columns I presume are fixed and
hence known. The total number of pieces of data is then
a*the number of columns.

You then need to assign each value to a variable and use
that variable to poulate the listbx using a for to
command, and using the activecell.offset to move from one
cell to the next to get each pice of data and then placing
that piece of data into the listbox using listbox.add and
the count value from above to set the number of rows
required for the listbox.

Hope this gets you started

DavidC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top