+ Reply to Thread
Results 1 to 10 of 10

Set VBA search function to only search one row and also not show duplicates?

  1. #1
    Registered User
    Join Date
    02-02-2012
    Location
    Canada
    MS-Off Ver
    Excel 2013
    Posts
    42

    Set VBA search function to only search one row and also not show duplicates?

    Hello,

    You guys have been a ton of help to me in the past. I'm hoping you can help today. In the attached spreadsheet you will find a "CutList Generator" I made this a few years back with tons of help from here. (I'm sorry the codes so messy)

    I recently added the search box on the side of the generator to allow for easier input of part descriptions. I got the code off of another post here and cant figure out how to make it do what I want.

    Here is what I want it to do:

    1. I want the List box to automatically show all of the entries in the Descriptions Column (column D), i also want the box to auto update as new entrys are put into the cutlist.

    2. I also would like it if it didn't show duplicates at all.

    That's basically it. I want more functionality yet but I want to challenge myself a bit and work out the other bit myself bore coming for more help lol.

    Any ideas or info is awesome! :)


    Ohhh and if someone just so happens to be looking at something in the code and is like "Hey you can do this better/easier by using... (insert code here)... " Than by all means let me know!

    NEW CUTTING LIST.xlsm

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Set VBA search function to only search one row and also not show duplicates?

    Any ideas or info is awesome!
    Fill your sample file with sample data.
    i also want the box to auto update as new entrys are put into the cutlist.
    You'll have to explain how the cutlist is updated. From the userform? If so, then call the paintbox1_change sub from wherever the update happens.

    Just with some quick fill data, the listbox appears to work as listed.

    To have a unique list, use a collection, because collections can't have duplicate data (well, keys actually). We take advantage of that by attempting to put all the data in the collection. The collection refuses to insert the duplicate data and because we have error reporting turned off, we can pass by without stopping. So we end up with a unique list.

    Please Login or Register  to view this content.
    Last edited by Tinbendr; 04-12-2014 at 07:41 PM.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    02-02-2012
    Location
    Canada
    MS-Off Ver
    Excel 2013
    Posts
    42

    Re: Set VBA search function to only search one row and also not show duplicates?

    This works exactly as I would like it to. Only thing I need to do yet is get it to search a column based on a variable.

    So basically I want to set a variable say: "searchnum" and based on the value of search num I want this to select a different column to pull values from.

    So if I set the value of "searchnum" to 3 I want it to search column d. and etc.

    I have tried some stuff but for whatever reason I cant even get it to search a specific column other than the first one, much less get it to pull those column values from a variable.

    I reattached the cutting list with the code that Tinbendr came up with (THANKYOU BTW!!!!)and some demo data so that everyone can see what types of data that get thrown into the sheet.


    NEW CUTTING LIST DEMO.xlsm

    [EDIT]

    I got the search by column working but I cant figure out how to set it to a variable... This is waht I have:

    Please Login or Register  to view this content.
    Last edited by TomToms; 04-23-2014 at 08:24 AM. Reason: Figured one part out and didn't want to double post

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Set VBA search function to only search one row and also not show duplicates?

    I'm still confused as how you intend to select the column?

  5. #5
    Registered User
    Join Date
    02-02-2012
    Location
    Canada
    MS-Off Ver
    Excel 2013
    Posts
    42

    Re: Set VBA search function to only search one row and also not show duplicates?

    Ill try to explain it as best I can.

    Basically I will make the list update based on what part of the form the user is working in. If they are typing in a detail number, the list box will start to show all of the entries already in the detail number column (column A)on the spreadsheet. If they are typing in a description the list box will show all of the previous entries in the description column (column D). I want to control this by the "_change" function. So On the text entry box for description for example. When someone types in anything I want it to change a variable to a certain number.

    Now when that variable changes I want the list box to start looking in a corresponding column for its entries. In this case I type in something to the description. It changes a variable, say "searchvar" to equal "D" and than the list box uses the value of searchvar to determine what column to display results from.

    This make a little more sense? I will draw pictures if I must lol.

    Thanks in advance

  6. #6
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Set VBA search function to only search one row and also not show duplicates?

    OK, I understand now.

    This will take a lot of coding to accomplish, but the premise is:
    1. Remove the Paintbox control.
    2. Whichever control the user is typing it will determine which column to search.
    a. Create a subroutine to fill the listbox. In each control change event, call the subroutine, passing the range (column) information.
    b. We'll have to store the active control name somewhere (probably the listbox tag property), so when the listbox item is double-clicked, the code will know the correct control to sent it to.

    Sound right?

  7. #7
    Registered User
    Join Date
    02-02-2012
    Location
    Canada
    MS-Off Ver
    Excel 2013
    Posts
    42

    Re: Set VBA search function to only search one row and also not show duplicates?

    Thats actually exactly what I want to do. you got it 100%.

  8. #8
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Set VBA search function to only search one row and also not show duplicates?

    OK, try this.

    The routine to fill the paintbox has been moved to the UpdateForm module.

    Each control that you want to search from has to have change event code call the ftnPaintBox.

    Look at the Detail Drawing and the Item Number textbox change events in the userform.

    I've left the drudgery of changing all the events to you.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    02-02-2012
    Location
    Canada
    MS-Off Ver
    Excel 2013
    Posts
    42

    Re: Set VBA search function to only search one row and also not show duplicates?

    I know this is like 5 months later but I have finally been given time to work on this again. So I ran back through that workbook you gave me, and the search function works good but for whatever reason it errors out whn I double click the searched item to insert it into the generator. Any ideas?

  10. #10
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Set VBA search function to only search one row and also not show duplicates?

    What is supposed to happen when you double click?

    The objects in the dblclick event do not exist. But I can't remember how it's supposed to work.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. IF(count(search) Function not working when search from text from a cell
    By joshnathan in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 10-09-2013, 05:13 AM
  2. [SOLVED] Search function to search if worksheet contains specified text
    By mougiasm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-07-2013, 02:50 PM
  3. Replies: 1
    Last Post: 10-18-2012, 05:52 AM
  4. Macro to search for duplicates
    By aharvestofhealth in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-21-2009, 04:24 PM
  5. search for duplicates
    By enyaw in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-22-2006, 10:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1