Solved

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

Posted on 2016-11-08
3
28 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 33

Accepted Solution

by:
Norie earned 500 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 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now