Excel List VBA Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maxamis4
    Recognized Expert Contributor
    • Jan 2007
    • 295

    Excel List VBA Question

    I have this sub i created for Excel. The idea is to populate multi column list box from values in an excel spreadsheet. I am stepping through the code which executes fine but no values are loaded in my list. Anyone have any ideas?

    Code:
    Private Sub cmdContact_Click()
    
    Dim cell As Range
    Dim Rng As Range
        
    'Me.lstEmployee.Clear 'Make sure the Listbox is empt
    
    
        With ThisWorkbook.Sheets("Employee Data")
            Set Rng = .Range("A2", .Range("A2").End(xlDown))
        End With
        
            For Each cell In Rng.Cells
                With lstEmployee
                    .AddItem cell.Value
                    .List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
                    .List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
                    .List(.ListCount - 1, 3) = cell.Offset(0, 3).Value
                    .List(.ListCount - 1, 4) = cell.Offset(0, 4).Value
    
                End With
            Next cell
    
    
    
    
    
    End Sub
  • maxamis4
    Recognized Expert Contributor
    • Jan 2007
    • 295

    #2
    Please ignore the question. I found the issue under a property within int he list box. Code works fine if anyone wants it.

    Comment

    • Zakoss
      New Member
      • Nov 2016
      • 6

      #3
      Passing by reference is the default in VBA. If you do not explicitly specify to pass an argument by value VBA will pass it by reference.

      Comment

      Working...