title: unable to populate combobox using .rowsource {vba excel}
body: <p>I'am a newbie in VBA excel and trying here to populate a combobox in a userform with data from a sheet. I defined address &amp; used the .rowsource property wherein code go through without any error but nothing populates on the combobox. Any help will be appreciated.</p>
  
  <p>Below is the code -</p>
  
  <p>Private Sub empSearchdb_Click()</p>
  
  <pre><code>Dim cell As Range
  Dim emptyRow As Long
  Dim rng As Range
  Dim ws1 As Worksheet
  Dim empSearchKeyword As String
  
  'Stop screen flickering
  Application.ScreenUpdating = False
  
  'setting worksheet
  Set ws1 = Sheets("EmployeeDetails")
  ws1.Activate
  
  'find last empty row
  emptyRow = WorksheetFunction.CountA(Range("A:A")) + 2
  
  'when nothing is selected
  If Me.empSearchL.ListIndex = -1 Then
  
      'from $A$1 to $J$lastrow-1
      Set rng = Range("$A$1", Cells(emptyRow - 1, 10))
  
      With Me.empDetails
          .RowSource = rng.Address
      End With
  </code></pre>
  
  <p><strong>New modified code -</strong> </p>
  
  <pre><code>Dim cell As Range
  Dim emptyRow As Long
  Dim rng As Range
  Dim ws1 As Worksheet
  Dim empSearchKeyword As String
  
  'Stop screen flickering
  Application.ScreenUpdating = False
  
  'setting worksheet
  Set ws1 = ActiveWorkbook.Sheets("EmployeeDetails")
  
  'find last empty row
  emptyRow = WorksheetFunction.CountA(Range("A:A")) + 2
  
  'from $A$1 to $J$lastrow-1
  Set rng = ws1.Range("$A$1", ws1.Cells(emptyRow - 1, 10))
  Set rng = ws1.Range("$A$1", "$J$10")
  
  
  'With your listbox do the following
  If Me.empSearchL.ListIndex = -1 Then
      With Me.empDetails
          'If nothing is selected, add a row source
          .ColumnCount = 10 'Otherwise you will only get 1 column
          .RowSource = rng.Address
      End With
  End if
  Application.ScreenUpdating = True
  </code></pre>