title: Populating a ListBox from search criteria entered into a TextBox in Excel VBA
body: <p>I have posted this problem before, however, I think it was overly complicated and I didn’t explain it very well.  This time I am just using a simple UserForm as an example.</p>
  
  <p>I want to populate a ListBox by entering search criteria in a Textbox.</p>
  
  <p>I have three columns:</p>
  
  <p><strong>Column A = Library Card Number</strong></p>
  
  <p><strong>Column B = Pupil Name</strong></p>
  
  <p><strong>Column C = Book Reference</strong></p>
  
  <p>I have a UserForm:</p>
  
  <p><strong>TextBox = txtlcn (for the Library Card Number)</strong></p>
  
  <p><strong>TextBox = txtpn (for the Pupil Name)</strong></p>
  
  <p><strong>TextBox = txtbr (for the Book Reference)</strong></p>
  
  <p><strong>Command Button = cmdfinddetails (Find Details)</strong></p>
  
  <p>What I want to do is change the TextBox ‘txtbr’ into a ListBox, so that I can see if a pupil has more than one book loaned out to them.  The process would be:</p>
  
  <ol>
  <li><strong>A pupil enters their Library Card Number in TextBox  ‘txtlcn’ and
  clicks on Command Button ‘cmdfinddetails’</strong></li>
  <li><strong>The code will search for that Pupil’s name and all the book
  references booked out to them.</strong></li>
  <li><strong>The book reference(s) will be displayed in a ListBox.</strong></li>
  </ol>
  
  <p>I have tried lots of things to do with RowSource but it always lists every pupil’s book reference.  Below is my sample code.</p>
  
  <pre><code>Private Sub cmdfinddetails_Click()
  Set xSht = Sheets("Library")
          Lastrow = xSht.Range("A" &amp; Rows.Count).End(xlUp).Row
          strSearch = txtlcn.Text
                      Set aCell = xSht.Range("A1:A" &amp; Lastrow).Find
  
  (What:=strSearch, LookIn:=xlFormulas, _
      LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
      MatchCase:=False, SearchFormat:=False)
  
        If Not aCell Is Nothing And txtpn.Value = "" Then
           GoTo libcardrefvalid      
       Else
  MsgBox "Oops! That Library Card does not exist. Please try again.", Title:="We LOVE Reading ;-)"
  txtlcn.Value = ""
          End If
      Exit Sub
  libcardrefvalid:
  
  row_number = 0
  Do
  DoEvents
  row_number = row_number + 1
  item_in_review = Sheets("Library").Range("A" &amp; row_number)
  If item_in_review = txtlcn.Text Then
  txtpn.Text = Sheets("Library").Range("B" &amp; row_number)
  txtbr.Text = Sheets("Library").Range("C" &amp; row_number)
  End If
  Loop Until item_in_review = ""
  
  End Sub
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thank you.</p>