Avatar of stephenlecomptejr
stephenlecomptejr
Flag for United States of America asked on

Excel VBA: How to add items to a multi-select listbox with two columns instead of one?

Excel VBA form:  How to add items to a multi-select listbox with two columns instead of one?

Please note the following code:
I get the yellow highlight on line item with Run-time error '13'.  type mismatch.
please note image attachments that show this as well.

All I'm doing is looping through the collection and adding to the two columns - the fullfilename found in variable sFile and the filename only in sFileOnly...

Me.ListBox_FilesFound(lCounter - 1, 0) = sFile

Open in new window


Private Sub FillListBox_FilesFound()
On Error GoTo Err_Proc

  Dim sFileName As String
  Dim sFilePath As String
  Dim lCounterFileTotal As Long
  Dim lCounter As Long
  Dim sFileOnly As String
  Dim colFiles As New Collection
  Dim vFile As Variant
  Dim sFile As String
  
  'setting up listbox:
  Me.ListBox_FilesFound.ColumnCount = 2
  Me.ListBox_FilesFound.ColumnWidths = "0;100"
  Me.ListBox_FilesFound.Clear
  
  sFileName = GetCurrentFileName

  'determine path
  sFilePath = FilePathOnly_feo(sFileName)
  txtFilePath = sFilePath
  
  RecursiveDir colFiles, sFilePath, "*.xls*", True
  
  lCounterFileTotal = colFiles.Count
  lCounter = 0
  'loops through all files found in RecursiveDir
  'but only through filenames that have states.
  For Each vFile In colFiles
  
    sFile = vFile
    lCounter = lCounter + 1
    sFileOnly = FileNameOnly_feo(sFile)
    
    Me.ListBox_FilesFound.AddItem
    Me.ListBox_FilesFound(lCounter - 1, 0) = sFile
    Me.ListBox_FilesFound(lCounter - 1, 0) = sFileOnly
    
    If IsNameOfUSStates(sFileOnly) = True Then
      ListBox_FilesFound(lCounter - 1, 0).Selected = True
      DoEvents
    End If
    
  Next vFile
  'lCounter = 0
  
Exit_Proc:
  Exit Sub
  
Err_Proc:
  Call LogError_feo(Err, Err.Description, "fAdjustFiles @ FillListBox_FilesFound")
  Resume Exit_Proc
End Sub

Open in new window

ee-error1.PNG
ee-error2.PNG
VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
stephenlecomptejr

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
stephenlecomptejr

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck