[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VBA: How to Populate Column Headers in Multicolumn List Box When Source is an Array?

Posted on 2016-11-08
3
Medium Priority
?
376 Views
Last Modified: 2016-11-16
Hello,

I'm using Excel 2013 and have a user form with a multicolumn list box. Because of filtering from controls (text box, combo box, etc) and other reasons I've chosen to populate the list box with an array rather than via row source. At this time, the row source vs array is non-negotiable. The multicolumn list box works quite well except that the row headers are blank.

My research reveals that if you provide a row source then Excel will identify the column headers but if your source is from an array then there is no way to put column headers in. I refuse to accept that and figure someone out there knows of some quirky workaround. Sometimes things are accomplished with unique tricks and hopefully someone here can think of something. I've looked throughout the web and haven't found any concrete solutions without binding data to a range... at which point you might as well go with row source.

Any thoughts on how to populate the column headers while using the array source? Thanks!
0
Comment
Question by:Phil_Consultant
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Norie earned 2000 total points
ID: 41879431
There is no way to have 'standard' column headers in a listbox populated from an array. *

However there are a no of workarounds that can be used to imitate, perhaps even better, the standard listbox column headers.

One that I prefer is to use a single row listbox that has the same no of columns and the same column widths as the listbox that will actually show the data.

That listbox would sit just above the main listbox and since it is a separate listbox could be formatted differently than the main one, eg different font, colours etc.

* Of course if you were to transfer the array to a range it can be done but you indicate that's not an option.
0
 
LVL 1

Author Comment

by:Phil_Consultant
ID: 41882715
Hi Norie,

I've considered your idea but one piece of information I accidentally left out is that the multicolumn list box has many columns thus scroll bars (both top/bottom and left/right). My understanding is that if I was to scroll the data left/right the columns wouldn't align. Thanks for the suggestion.
0
 
LVL 35

Expert Comment

by:Norie
ID: 41882797
You probably could do something to keep the headers aligned with the columns when scrolling but I've a feeling it would probably involve using Windows API.

Have you considered using a ListView control instead of a Listbox?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question