View Single Post
 
Old 05-29-2019, 07:32 PM
NoSparks NoSparks is offline Windows 7 64bit Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

You don't need to loop through an array using AddItem to populate a listbox, you can make the listbox.list equal to the array,
and if the array is more than 1 column... so is the list but you need to adjust the column count property of the list box.
This site is of interest for populating combo and list boxes.

For what you've asked, I'd do this...
In module1, replace
Code:
Global gCodesListArr As Variant
Global gDetailsListArr As Variant
with
Code:
Global gCodesAndDetailsListArr As Variant
In Worksheet_SelectionChange, replace
Code:
      gCodesListArr = Sheets("Codes").Range("A3:A67").Value
      gDetailsListArr = Sheets("Codes").Range("B3:B67").Value
with
Code:
      gCodesAndDetailsListArr = Sheets("Codes").Range("A3:B67").Value
In UserForm_Activate, replace
Code:
For Each element In gCodesListArr
  Me.ListBox1.AddItem element
  Next element
with
Code:
Me.ListBox1.List = gCodesAndDetailsListArr
Hope that helps.
Reply With Quote