+ Reply to Thread
Results 1 to 8 of 8

Function to Return Range of matches...

  1. #1
    Registered User
    Join Date
    03-11-2017
    Location
    Wolverhampton, UK
    MS-Off Ver
    2016
    Posts
    3

    Function to Return Range of matches...

    Hi, I've got some data in a sheet as below

    Please Login or Register  to view this content.
    is there a function I can use to return the range where the text in a given column (ie. A) matches 'Management' ?

    i.e the result for the example above would be A2:A6 ?

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Function to Return Range of matches...

    Cell with first occurrence:
    =ADDRESS(MATCH("Management",$A$1:$A$13,0),1)

    Cell with last occurrence:
    =ADDRESS(LOOKUP(2,1/($A$1:$A$13="Management"),ROW($A$1:$A$13)),1)
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Function to Return Range of matches...

    One way, where D2 contains Management, is this array formula so use CTRL+SHIFT+ENTER to commit formula

    =ADDRESS(MIN(IF($A$1:$A$13=D2,ROW($A$1:$A$13))),1,4 ) & ":" & ADDRESS(MAX(IF($A$1:$A$13=D2,ROW($A$1:$A$13))),1,4)


    Alternative normal formula
    =ADDRESS(MATCH(D2,$A$1:$A$13,0),1,4)&":"&ADDRESS(MATCH(D2,$A$1:$A$13,0)+COUNTIF($A$1:$A$13,D2)-1,1,4)
    Last edited by Andy Pope; 03-11-2017 at 06:59 AM.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Function to Return Range of matches...

    As a matter of interest: whay do you want this? Are you wanting to use these in another formula, or are the addresses themselves the final result?

  5. #5
    Registered User
    Join Date
    03-11-2017
    Location
    Wolverhampton, UK
    MS-Off Ver
    2016
    Posts
    3

    Re: Function to Return Range of matches...

    Cheers Glenn,

    I should have said above but didn't for simplicity, which was probably a mistake - the lookup is being done from another sheet, This is what I've got in the cell I need to do the lookup in...

    =VLOOKUP(C80,'Discplines & Levels'!ADDRESS(MATCH(B80,$A$1:$A$100,0),1):ADDRESS(LOOKUP(2,1/($A$1:$A$100=B80),ROW($A$1:$A$100)),1),4,FALSE)

    Cell C80 contains the value I need to find, B80 contains the Discipline (i.e. Management). The list of disciplines as partly shown in the Orginal post is in Column A, covered by the A1 to A100 range.

    This is what it was before
    =VLOOKUP(C80,'Discplines & Levels'!$B$25:$E$28,4,FALSE)

    Basically its the 'Discplines & Levels'!$B$25:$E$28 bit that I'm trying to make dynamic - at the moment I'm having to code the ranges by hand.

    I'm sure the ADDRESS functions you used would work, but I need to somehow join the worksheet name onto the front of the range?

    To give the context, I'm building up a series of SQL insert statements from the data and need to find the ID for the specific Level ID from column E in the 'Discplines & Levels' worksheet for the Discipline - i.e. 'Management'.

    So management contains 4 levels, say IDs 4,5,6,7, I'm using the VLookup to find the ID for Management Level 4, but I need to find the range for "Management" so that the VLookup can the work on that range.
    Last edited by SteveMG; 03-11-2017 at 07:04 AM.

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Function to Return Range of matches...

    Not sure I completely follow you, but...
    Attached Files Attached Files

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Function to Return Range of matches...

    using Glenn's file as the example. Rather than ADDRESS you can use INDEX to create top left and bottom right range references.

    =VLOOKUP(E2,INDEX(Sheet1!$B$1:$B$13,MATCH(Sheet2!D2,Sheet1!$A$1:$A$13,0)):INDEX(Sheet1!$D$1:$D$13,MATCH(D2,Sheet1!$A$1:$A$13,0)+COUNTIF(Sheet1!$A$1:$A$13,D2)-1),3,FALSE)
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    03-11-2017
    Location
    Wolverhampton, UK
    MS-Off Ver
    2016
    Posts
    3

    Re: Function to Return Range of matches...

    Cheers Andy and Glenn, that worked perfectly. Substituting the cells for the cells in my spreadsheet was half an hours work, 15 min of which was fighting Excel as it wanted to put references to the different excel file every time I alt-tabbed to it! lol - Quickly solved that, thankfully I've got a big screen and could put about 4 windows into the 2 docs side by side!

    But end result is that it works perfectly, that's a major pain the backside fixed

+ 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. [SOLVED] Macro for Message box to return adjacent cell value of all the matches in a column range
    By Saranya A in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-07-2016, 06:24 AM
  2. [SOLVED] Search text in range, if matches, return match value
    By ShakJames in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-13-2016, 06:12 AM
  3. Formula to return multiple matches within a range, ranked
    By chococ in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-25-2016, 07:52 AM
  4. [SOLVED] Return multiple matches using index function
    By sbabu16 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-27-2015, 05:01 AM
  5. [SOLVED] Return a value if a number is in a range, even, and then matches the street
    By pixelninja in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 03-16-2014, 05:45 PM
  6. Return Range of Cells whose title matches given cell
    By Whimsical in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-07-2013, 03:29 AM
  7. VLOOKUP - Return sum of all matches in Range?
    By Wiggz in forum Excel General
    Replies: 3
    Last Post: 01-25-2007, 06:42 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