Populating a ListBox with Columns Using Pre-Filled Array

jbennett01

New Member
Joined
Apr 25, 2018
Messages
12
Office Version
  1. 2016
Platform
  1. Windows
How can I get this ListBox to display the states in 2 columns. I've tried a few different things, including modifying the ListBox properties, tried in code. The solutions I've found online all deal with a dynamic array and I could not figure out how to convert that to a static one. This is code from the Form object and the code which calls the Form.

VBA Code:
Private Sub UserForm_Initialize()

    ' Declare variables
    lstStateCodes1 = Array("AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", "KS", _
        "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO")
    lstStateCodes2 = Array("MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", _
        "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VI", "VT", "WA", "WI", "WV", "WY")
    With Me.lstStateList
        .ColumnCount = 2
        .ColumnWidths = 50
        .List(1, 0) = lstStateCodes1
        .List(2, 0) = lstStateCodes2
    End With
    lstForeclosureType = Array("Judicial", "Non Judicial")
    lstOccupancyStatus = Array("Abandoned", "Occupied By Unknown", "Owner Occupied", "Removed or Destroyed", "Tenant Occupied", "Unknown", "Vacant")
    lstFCLStatus = Array("Active", "Inactive", "On Hold")

End Sub

Code:
sub test ()
    Dim frmReport As New frmManualUploadReport

    Load frmReport
    frmReport.Show
    Unload frmReport

End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Maybe like this:
VBA Code:
Private Sub UserForm_Initialize()

    ' Declare variables
    lstStateCodes = Array("AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", "KS", _
        "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", _
        "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VI", "VT", "WA", "WI", "WV", "WY")
    With Me.lstStateList
        .ColumnCount = 2
        .ColumnWidths = 50
        On Error Resume Next
        For i = LBound(lstStateCodes) To UBound(lstStateCodes) / 2
          .AddItem
          .List(i, 0) = lstStateCodes(i)
          .List(i, 1) = lstStateCodes(((UBound(lstStateCodes) / 2) + 1) + i)
        Next
        On Error GoTo 0
    End With
    lstForeclosureType = Array("Judicial", "Non Judicial")
    lstOccupancyStatus = Array("Abandoned", "Occupied By Unknown", "Owner Occupied", "Removed or Destroyed", "Tenant Occupied", "Unknown", "Vacant")
    lstFCLStatus = Array("Active", "Inactive", "On Hold")
End Sub
 
Upvote 0
Maybe like this:
VBA Code:
Private Sub UserForm_Initialize()

    ' Declare variables
    lstStateCodes = Array("AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", "KS", _
        "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", _
        "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VI", "VT", "WA", "WI", "WV", "WY")
    With Me.lstStateList
        .ColumnCount = 2
        .ColumnWidths = 50
        On Error Resume Next
        For i = LBound(lstStateCodes) To UBound(lstStateCodes) / 2
          .AddItem
          .List(i, 0) = lstStateCodes(i)
          .List(i, 1) = lstStateCodes(((UBound(lstStateCodes) / 2) + 1) + i)
        Next
        On Error GoTo 0
    End With
    lstForeclosureType = Array("Judicial", "Non Judicial")
    lstOccupancyStatus = Array("Abandoned", "Occupied By Unknown", "Owner Occupied", "Removed or Destroyed", "Tenant Occupied", "Unknown", "Vacant")
    lstFCLStatus = Array("Active", "Inactive", "On Hold")
End Sub
Unfortunately, that did not work, though I appreciate the effort. For now, I've just given up :)
 
Upvote 0
What do you mean by didn't work? I've tested it.
What is the error exactly you are getting?
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top