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
Solved

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

809 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