Load Data Meeting Condition Into Listbox

  • Hi guys


    im using an adapted version of Roys database. Heres my code:



    This works fine for the first part - i.e it loads the data into the textboxes, and loads the headers and first search result into the listbox. However it always only loads the first search result, not all.


    Does anyone know why this might be? If its not clear I can post a simplified example of the working spreadsheet.


    Thanks in advance[hr]*[/hr] Auto Merged Post;[dl]*[/dl]Ive uploaded an example to assist anyone kind enough to assis me :)


    Thanks

  • Re: Load Data Into Listbox


    I assume the problem is when searching for Code.


    The problem is whilst scanning for matching codes the first match is used to populate the textboxes. At the end of the search routine a call is made to cmbFindcodeAll_Click


    This then does another scan but uses the exact matching Code and therefore only returns a single match.


    It maybe better to build the array of matched information in the search routine.

    [h4]Cheers
    Andy
    [/h4]

  • Re: Load Data Into Listbox


    Hover over FIND and read the page on the Find Method. It shows use of a loop restricted by COUNTIF to find all occurences.


    Or, use Advanced or AutoFilter to copy results meeting conditions to another range or Worksheet.

  • Re: Load Data Meeting Condition Into Listbox


    Thank you both Andy and Dave for your replies. Makes sense.


    However on my attached example, searching by name works fine - it returns all the results. Its just by code that dosnt work. Ive printed off the subs for search by name and search by code and they seem to be the exact same (apart from different ranges to search, of course)


    Any ideas why searching by name works ,but the search ny code only returns the one?


    Thanks again

  • Re: Load Data Meeting Condition Into Listbox


    Andy has told you why the code doesnt work.


    Quote from Andy Pope

    The problem is whilst scanning for matching codes the first match is used to populate the textboxes.


    If you search for the code "K". The first macro "cmbFindcode" changes textbox2 to the first found value ie "KI", so when the second sub routine "cmbFindcodeAll"
    runs it is searching for "KI" instead of "K".


    ie comment this block of code in the "cmbFindcodeAll" sub and you will find it works.


    Code
    .TextBox1.Value = c.Offset(0, -1).Value
          .TextBox2.Value = c 'Definately this line
          .TextBox3.Value = c.Offset(0, 1).Value
  • Re: Load Data Meeting Condition Into Listbox


    Thanks reafidy. I apologise that I never picked this up with Andys reply.


    Ill read more carefully the next time
    Thanks again, your time is appreciated

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!