+ Reply to Thread
Results 1 to 11 of 11

Return multiple values to a UserForm using one search term

  1. #1
    Registered User
    Join Date
    06-28-2013
    Location
    London, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    69

    Return multiple values to a UserForm using one search term

    Hi all,

    I am trying to debug this code. I am using a search function to retrieve values from a workbook and return them to multiple textboxes in my userform. So each record is assigned a projectID. Multiple records may have the same ProjectID to a maximum of 4 so there are 4 different sets of textboxes. The code below works but there are some problems:

    1. It doesn't return every value
    2. the values are returned in the wrong order (it should grab the values and return them in order from top to bottom, currently it has reversed this order)

    Any help would be greatly appreciated!

    Please Login or Register  to view this content.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Return multiple values to a UserForm using one search term

    Can you attach your workbook? It is very difficult to analyze this code out of context, and your description is not complete. Therefore the references in your description to "record" and "projectID" are mysterious, and I have no idea what you mean by, "It doesn't return every value.". It would be helpful to see the form and be able to run modified code to see results. It would also be helpful to be able to see the data on the worksheet.

    That being said, I have some comments based on my best guess as to what's going on.

    Your Sub statement and declarations are not provided. I recommend using Option Explicit to require declaration of all variables.

    I cannot figure out why you are using DoEvents. It returns control to the operating system to allow queued events to be processed. No clue as to why that would be needed here.

    The following line of code does not do anything useful:
    Please Login or Register  to view this content.
    As it stands this will put you in an infinite loop if the value in A1 is not blank.

    Why do you start with item_in_review2? What happened to item_in_review1?

    You restart on row 1 each loop. I would think you should start each loop where the previous one left off.

    I cannot figure out your strategy for incrementing the row number each time through each loop. In the first loop you do not increment at all (see comment above). Then you increment by 1, then in the next loop by 2, and then 3. Why would you want to look only at every third record by the time you get to the last loop? Maybe this is a logic error.

    The reason that it shows the found values from bottom to top is that the loop continues until cell "A" & row number is blank. Therefore the values left in the textboxes are the last ones found. Instead, you should exit the loop the first time you find a match.

    Your indentation is a bit eccentric. The convention is to have Do and Loop at the same level, then indent the code in between them. Similar for If and End If, and all other control structures.

    A With can streamline the appearance of the code (and also make it more efficient but that is probably not an issue here) since it always refers to the same sheet.

    I have shown the code with some modifications that I think make some corrections. However, this is a bit shooting in the dark without more complete information.

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    06-28-2013
    Location
    London, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Return multiple values to a UserForm using one search term

    6StingJazzer,

    Thank you for the feedback and response. I am very very new to VBA and am attempting to learn by doing. I will prepare a workbook with this code and post it to the forum at some point tomorrow. I will attempt to explain what I am hoping to accomplish then. I understand what is here is vague but I am unsure how to explain the problems I am running into due to my lack of experience with code and VBA.

    Thanks again for the response!

    Wolfman

  4. #4
    Registered User
    Join Date
    06-28-2013
    Location
    London, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Return multiple values to a UserForm using one search term

    Hey Jeff I've prepared a workbook with the code I posted here before. The idea is that there are multiple permits to one project ID. I want to be able to call upon all of the available permit information using the projectID (max of 4 permit requirements per ProjectID). I then would like to be able to edit them from the UserForm (which is the reason I am not using a Listbox). Let me know what you think!

    Wolf
    Attached Files Attached Files

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Return multiple values to a UserForm using one search term

    Wolf,

    Here is your workbook [clapforthewolfman=SampleWorkbook- Search and Edit Debug.xlsm] with the code I posted above replacing your original code. The only change I made was to add variable declarations, and code to blank out the fields on the form to initialize if you do a search for another project.

    BTW cool username. I was in high school when that song came out.

  6. #6
    Registered User
    Join Date
    06-28-2013
    Location
    London, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Return multiple values to a UserForm using one search term

    Thanks for this! Search function works very well. Now what can be done to make edits to the data retrieved?

  7. #7
    Registered User
    Join Date
    06-28-2013
    Location
    London, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Return multiple values to a UserForm using one search term

    And yeah the GUess Who are awesome!

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Return multiple values to a UserForm using one search term

    Quote Originally Posted by clapforthewolfman View Post
    Thanks for this! Search function works very well. Now what can be done to make edits to the data retrieved?
    I can give you the strategy, not sure how much help you need coding it.

    The most straightforward way is to keep an array (or four variables) that keep track of what row each match was found on. These need to be declared globally, above the first Sub. You would set these values in each of the four blocks where you identify a match. Then create a Sub for each control (you have 16 of them) to handle the Change event. The Change event will take the new value in the control and then update the corresponding cell in the worksheet. It will look up the row in the array (or four variables), and each control always corresponds to the same column.

    This is a very strategic explanation. I think you will get more out of this if you try to implement it yourself but I can provide the code if you need it. It will just take a little time to get to it.

  9. #9
    Registered User
    Join Date
    06-28-2013
    Location
    London, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Return multiple values to a UserForm using one search term

    Quote Originally Posted by 6StringJazzer View Post
    I can give you the strategy, not sure how much help you need coding it.

    The most straightforward way is to keep an array (or four variables) that keep track of what row each match was found on. These need to be declared globally, above the first Sub. You would set these values in each of the four blocks where you identify a match. Then create a Sub for each control (you have 16 of them) to handle the Change event. The Change event will take the new value in the control and then update the corresponding cell in the worksheet. It will look up the row in the array (or four variables), and each control always corresponds to the same column.

    This is a very strategic explanation. I think you will get more out of this if you try to implement it yourself but I can provide the code if you need it. It will just take a little time to get to it.
    I appreciate the help! I am going to try to use this as a guide but my VBA knowledge is rather limited. If you could send code for this it would be greatly appreciated. If I find a way between now and when you have a chance to get to this I will post it on this thread.

    Thanks!

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Return multiple values to a UserForm using one search term

    Here is a modification. [clapforthewolfman=SampleWorkbook- Search and Edit Debug.xlsm]

    I also noticed that you are getting data from columns with headings that don't match the labels on the text boxes on your form. I modified the code so they match.

    I also set up another sheet called Status Values with a list of possible status values to populate the comboboxes. You can change this list to be whatever you want, but it must start in A1.

  11. #11
    Registered User
    Join Date
    06-28-2013
    Location
    London, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Return multiple values to a UserForm using one search term

    Wow this is perfect! I am marking this as solved. Jeff you are the dude!

    http://31.media.tumblr.com/tumblr_kp...26qlo1_500.gif
    Last edited by clapforthewolfman; 07-24-2013 at 03:37 PM. Reason: bad link

+ 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. Macro to return multiple values from search value
    By Mr Low in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-11-2012, 02:00 PM
  2. Search list and return multiple values
    By MarVil85 in forum Excel General
    Replies: 1
    Last Post: 06-23-2012, 03:46 PM
  3. Search for term in multiple cells
    By Snowtoad in forum Excel General
    Replies: 1
    Last Post: 08-13-2010, 02:25 AM
  4. lookup serch term and return sum of all values
    By soilcon1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-21-2005, 08:10 PM
  5. [SOLVED] Search multiple values to return single values
    By JANA in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-27-2005, 12:05 PM

Tags for this Thread

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