+ Reply to Thread
Results 1 to 9 of 9

Search array for multiple criteria, then write results sequentially to specified cells

  1. #1
    Registered User
    Join Date
    08-21-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Search array for multiple criteria, then write results sequentially to specified cells

    Hello,

    First time poster long time forum guest browser.

    I have encountered a problem I cannot seem to make work with various CSE functions to my satisfaction.

    I have an array which I would like to search based on two criteria to return a value from an adjacent cell that meets the criteria to a specific cell in a different sheet within the workbook. The macro then continues to search the array for any other rows matching the criteria and then writes the result to the cell below the previous output cell.

    The attached outlines a simplified version of what I am trying to achieve. Where the first colum in the array contains the value(s) that I want returned if the criteria in the adjacent two columns are met, with all lookup values in column meeting the criteria being written sequentially underneath the heading in the adjacent sheet.

    The purpose of the macro is to be applied to a sheet with multiple geographic locations (I have used shelfs and aisles as an example) represented visually with the array being dynamic. Placing restrictions on the use of filter options.

    Any guidance would eb greatly appreciated. If I'm barking up the wrong tree with thinking a macro is appropriate I'd love to hear any other way of achieving this goal.

    Thanks for your help in advance!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search array for multiple criteria, then write results sequentially to specified cells

    I am not sure what you are looking for, but a simple formula in B5

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-21-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Search array for multiple criteria, then write results sequentially to specified cells

    Thats almost exactly what I need, however, I need it to return all unit numbers that meet the criteria in the array. I.e your formula returns "S38", but I would like a function that retuns in teh cell immediately below B5 the next value that meets the criteria (in this case "S34"). Which is why i think a macro may be required.

    Any ideas as to how to shoehorn teh formula to achieve this?

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search array for multiple criteria, then write results sequentially to specified cells

    Code attached.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-21-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Search array for multiple criteria, then write results sequentially to specified cells

    Looks like your code does exactly what I need. Only issue is when I attempt to use teh code in my less simplified work book I get a 'Runtime Error (9); Script out of range'.
    Debugging gets me to

    Please Login or Register  to view this content.
    With the error at the "TT = Join$(Array(X(i, 2), X(i, 3)))"

    You will notice I have changed the reference cells to suit my sheet.

    Is this error occuring because the 'i' value is set to 2 and I have changed the reference position?

    Thanks for your fantastic help so far!
    Last edited by BraedonS; 08-21-2013 at 07:59 PM.

  6. #6
    Registered User
    Join Date
    08-21-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Search array for multiple criteria, then write results sequentially to specified cells

    In the case of the example. If I edit the code to apply to the next (from left to right) subject area (as per code below) I get the runtime error.

    What other parts of the code should I adjust to make it function for outputs in other areas of the output sheet?
    Last edited by BraedonS; 08-21-2013 at 07:59 PM.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Search array for multiple criteria, then write results sequentially to specified cells

    For your workbook posted.
    Please Login or Register  to view this content.

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Search array for multiple criteria, then write results sequentially to specified cells

    See if ths workbook helps, no VBa involved.

    Select from the drop-downs in C4:D4

    Note that E5 is an array formula, Confirm with Ctrl+Shift+Enter not just Enter Before dragging Down.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search array for multiple criteria, then write results sequentially to specified cells

    Script out of range means your data are outside the boundary of the array
    I was too lazy to use current region which may not work with your actual sheet. Use a range to load the data in to array instead of current region.
    Please Login or Register  to view this content.
    If you are getting error on these lines it is because the data have not picked up in the current region.
    Please Login or Register  to view this content.
    Refers to the matching column if your data are in column A-C, so A is one, B is 2 and soon

+ 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. Search Workbook for cells that meet multiple criteria and return results from rows
    By CFritz7 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-27-2013, 04:41 PM
  2. Search by Multiple Criteria, Put All Results into Drop Down List
    By Jeff C in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-27-2012, 02:54 PM
  3. User Form to Search multiple Criteria to return multiple Results
    By Calieth in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-16-2011, 11:57 AM
  4. Replies: 2
    Last Post: 07-15-2010, 03:05 PM
  5. Replies: 2
    Last Post: 10-31-2005, 10:05 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