Solved

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

Posted on 2016-11-08
3
75 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 34

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 34

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

724 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